Using current time in UTC as default value in PostgreSQL Using current time in UTC as default value in PostgreSQL postgresql postgresql

Using current time in UTC as default value in PostgreSQL


A function is not even needed. Just put parentheses around the default expression:

create temporary table test(    id int,     ts timestamp without time zone default (now() at time zone 'utc'));


Still another solution:

timezone('utc', now())


Wrap it in a function:

create function now_utc() returns timestamp as $$  select now() at time zone 'utc';$$ language sql;create temporary table test(  id int,  ts timestamp without time zone default now_utc());