Re: UUID v7
Aleksander Alekseev <aleksander@timescale.com>
From: Aleksander Alekseev <aleksander@timescale.com>
To: pgsql-hackers mailing list <pgsql-hackers@postgresql.org>
Cc: Przemysław Sztoch <przemyslaw@sztoch.pl>, Andrey Borodin <x4mmm@yandex-team.ru>, Sergey Prokhorenko <sergeyprokhorenko@yahoo.com.au>, Jelte Fennema-Nio <postgres@jeltef.nl>, Nick Babadzhanian <pgnickb@gmail.com>, Mat Arye <mat@timescaledb.com>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>, Tom Lane <tgl@sss.pgh.pa.us>, Daniel Gustafsson <daniel@yesql.se>, Matthias van de Meent <boekewurm+postgres@gmail.com>, Nikolay Samokhvalov <samokhvalov@gmail.com>, "Kyzer Davis (kydavis)" <kydavis@cisco.com>, Andres Freund <andres@anarazel.de>, "brad@peabody.io" <brad@peabody.io>, Kirk Wolak <wolakk@gmail.com>
Date: 2024-01-19T11:07:31Z
Lists: pgsql-hackers
Hi, > No. > > Timestamp and TimestampTz are absolutely the same thing. The only > difference is how they are shown to the user. TimestampTz uses session > context in order to be displayed in the TZ chosen by the user. Thus > typically it is somewhat more confusing to the users and thus I asked > whether there was a good reason to choose TimestampTz over Timestamp. > > > Theoretically, you're right. But look at this example: > > SET timezone TO 'Europe/Warsaw'; > SELECT extract(epoch from '2024-01-18 9:27:30'::timestamp), extract(epoch from '2024-01-18 9:27:30'::timestamptz); > > date_part | date_part > ------------+------------ > 1705570050 | 1705566450 > (1 row) > > In my opinion, timestamptz gives greater guarantees that the time internally is in UTC and the user gets the time in his/her time zone. I believe you didn't notice, but this example just proves my point. In this case you have two timestamps that are different _internally_, but the way they are _shown_ is the same because the first one is in UTC and the second one in your local session timezone, Europe/Warsaw. extract(epoch ...) extract UNIX epoch, i.e. relies on the _internal_ representation. This is why you got different results. This demonstrates that TimestampTz is a permanent source of confusion for the users and the reason why personally I would prefer if UUIDv7 always used Timestamp (no Tz). TimestampTz can be converted to TimestampTz by users who need them and have experience using them. -- Best regards, Aleksander Alekseev
Commits
-
Fix timestamp overflow in UUIDv7 implementation.
- a5419bc72e22 18.0 landed
-
Add UUID version 7 generation function.
- 78c5e141e9c1 18.0 landed
-
Add some UUID support functions
- 794f10f6b920 17.0 landed