I have a column of the TIMESTAMP WITHOUT TIME ZONE type and would like to have that default to the current time in UTC. Getting the current time in UTC is easy:
(in the following code, you should substitute 'UTC' for zone and now() for timestamp)
timestamp AT TIME ZONE zone - SQL-standard-conformingtimezone(zone, timestamp) - arguably more readableThe function timezone(zone, timestamp) is equivalent to the SQL-conforming construct timestamp AT TIME ZONE zone.
'UTC') or as an interval (e.g., INTERVAL '-08:00') - here is a list of all available time zonesnow() returns a value of type timestamp (just what we need) with your database's default time zone attached (e.g. 2018-11-11T12:07:22.3+05:00).timezone('UTC', now()) turns our current time (of type timestamp with time zone) into the timezonless equivalent in UTC.SELECT timestamp with time zone '2020-03-16 15:00:00-05' AT TIME ZONE 'UTC' will return 2020-03-16T20:00:00Z.Docs: timezone()