Re: selecting timestamp

From: Joe Conway <mail(at)joeconway(dot)com>
To: chris <chrisk(at)pgsqlrocket(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: selecting timestamp
Date: 2018-02-27 20:33:46
Message-ID: 2d002e06-5da4-948b-31c6-0ba367164464@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/27/2018 12:16 PM, chris wrote:
>
> What is the best way of selecting current timestamp in UTC? 
>
> SELECT
> CURRENT_TIMESTAMP   as ct1
> ,timezone('UTC',CURRENT_TIMESTAMP) as ct2
> ,timezone('utc',now()) as ct3
> ,CURRENT_TIMESTAMP at time zone 'UTC' as ct4
> ,NOW() at time zone 'utc' as ct5

Depends on whether you want a volatile or stable answer:

\x
SELECT clock_timestamp(),
clock_timestamp() AT TIME ZONE 'UTC',
now(),
now() AT TIME ZONE 'UTC'
FROM generate_series(1,3);
-[ RECORD 1 ]---+------------------------------
clock_timestamp | 2018-02-27 12:30:10.46699-08
timezone | 2018-02-27 20:30:10.466991
now | 2018-02-27 12:30:10.466692-08
timezone | 2018-02-27 20:30:10.466692
-[ RECORD 2 ]---+------------------------------
clock_timestamp | 2018-02-27 12:30:10.467017-08
timezone | 2018-02-27 20:30:10.467017
now | 2018-02-27 12:30:10.466692-08
timezone | 2018-02-27 20:30:10.466692
-[ RECORD 3 ]---+------------------------------
clock_timestamp | 2018-02-27 12:30:10.467023-08
timezone | 2018-02-27 20:30:10.467023
now | 2018-02-27 12:30:10.466692-08
timezone | 2018-02-27 20:30:10.466692

HTH,

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hadi Moshayedi 2018-02-27 20:37:28 index-only-scan when there is an index on all columns
Previous Message David G. Johnston 2018-02-27 20:26:27 Re: selecting timestamp