I have a table like this.
create table public.test123
(id int not null primary key, dt timestamp null default clock_timestamp());
I then insert into it from 2 different client sessions, the first session is from PG Admin, the second one is from DBeaver.
In the first session when I run
show timezone;it returnsUTC.
So this session's timezone isUTC. So from this session I do an insert as follows.insert into public.test123(id) values (1);In the second session I have timezone
America/New_Yorkand I do this.insert into public.test123(id) values (2);
I run the two inserts just a few seconds apart from each other.
But I get two very different values in the DB e.g.
id|dt |
--|-------------------|
1|2020-06-05 14:38:18|
2|2020-06-05 10:38:26|
I always thought that in such scenario the clock_timestamp() call is executed on the server, and the timezone of the client session should not matter. And I expected to get two values which are a few seconds apart, and not 4 hours apart.
What am I missing?
And also, is there any way to get a timestamp independent of the client session's timezone?
How can I create a column with default timestamp values which are really independent on the client session's timezone?
timestamp with time zone. I am not sure I quite get it, but this seems to work fine for my use case. By defaulttimestampmeanstimestamp without time zone.