Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a postgres column with a default timestamp value of epoch?

Tags:

sql

postgresql

I want to create a timestamp column with a default value of epoch. How can I do it? This, and all the variations I've tried don't work:

...
last_viewed_at     TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT TIMESTAMP "epoch",
...
like image 848
jbrown Avatar asked Sep 28 '15 20:09

jbrown


1 Answers

It's all about double quotes vs single quotes. Double quotes are for identifiers so you want:

...
last_viewed_at     TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT TIMESTAMP 'epoch',
...

fiddle

like image 106
Jakub Kania Avatar answered Oct 03 '22 04:10

Jakub Kania