Reputation: 4230
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
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
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
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