Adi
Adi

Reputation: 4230

How to get epoch time in Redshift?

In my schema I have a created_on field. I want to assign EPOCH time value to it automatically on insert. How to achieve that?

Upvotes: 2

Views: 4526

Answers (4)

Pukhraj soni
Pukhraj soni

Reputation: 2140

SELECT EXTRACT(EPOCH FROM now());

Upvotes: 0

wiltonio
wiltonio

Reputation: 141

RedShift does not have now() but has getdate() instead, so this would be the expression to get the epoch:

SELECT EXTRACT(EPOCH FROM GETDATE());

Upvotes: 1

Rahul Gupta
Rahul Gupta

Reputation: 1802

select date_part(epoch,sysdate)::int

If I’ve made a bad assumption please comment and I’ll refocus my answer.

Upvotes: 4

Łukasz Kamiński
Łukasz Kamiński

Reputation: 5930

On PostgreSQL (from with redshift was forked) you would do it like this:

ALTER TABLE sometable ALTER COLUMN created_on SET DEFAULT EXTRACT(EPOCH FROM now())

Maybe it works in redshift as well.

Upvotes: 1

Related Questions