Different NOW() values in default constraint and a function

Moderator: NorbertKrupa

Post Reply
dkultasev
Newbie
Newbie
Posts: 2
Joined: Fri Sep 23, 2016 10:07 am

Different NOW() values in default constraint and a function

Post by dkultasev » Fri Sep 23, 2016 10:17 am

Could anyone explain what is going on... I have following table:

Code: Select all

CREATE TABLE public.test
(
    a int,
    UpdateDate timestamp NOT NULL DEFAULT ('now()')::timestamptz
);

INSERT INTO public.test (a) values (1);
SELECT *, NOW() FROM public.test;
And the output is:
a UpdateDate NOW
1 2016-09-23 05:14:14 2016-09-23 12:14:15
Why the time differs by 7h? I believe that it is related to timezones somehow but ...

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Different NOW() values in default constraint and a function

Post by JimKnicely » Fri Sep 23, 2016 4:04 pm

Hi,

This is what I get:

Code: Select all

dbadmin=> CREATE TABLE public.test
dbadmin-> (
dbadmin(>     a int,
dbadmin(>     UpdateDate timestamp NOT NULL DEFAULT ('now()')::timestamptz
dbadmin(> );
CREATE TABLE

dbadmin=>
dbadmin=> INSERT INTO public.test (a) values (1);
 OUTPUT
--------
      1
(1 row)

dbadmin=> SELECT *, NOW(), NOW()::timestamptz FROM public.test;
 a |         UpdateDate         |              NOW              |              NOW
---+----------------------------+-------------------------------+-------------------------------
 1 | 2016-09-23 11:02:11.520683 | 2016-09-23 11:02:11.520683-04 | 2016-09-23 11:02:11.520683-04
(1 row)
What is your timezone set to?

Code: Select all

dbadmin=> show timezone
dbadmin-> ;
   name   |     setting
----------+------------------
 timezone | America/New_York
(1 row)

dbadmin=> \! echo $TZ
America/New_York
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “General”