Inconsistent time zone handling in timetz

Поиск
Список
Период
Сортировка
Искать

Inconsistent time zone handling in timetz

От:
miracee <sho@miracee.de>
Дата:
Hi,

I came across this issue yesterday during one of my PostgreSQL training courses. We were using PostgreSQL 18.7.

I used PostgreSQL 17.9 to reproduce the issue.

# SELECT '10:00 CET'::timetz;

   timetz
-------------
 10:00:00+01
(1 row)

# SELECT '10:00 Europe/Berlin'::timetz;

ERROR: invalid input syntax for type time with time zone: "10:00 Europe/Berlin"
LINE 1: SELECT '10:00 Europe/Berlin'::timetz;

There is another issue with timetz.

The session time zone is set to UTC:

# SHOW timezone;

 TimeZone
----------
 Etc/UTC

With timestamptz, both time zone specifications work correctly:

# SELECT '2026-11-17 10:00 CET'::timestamptz;

      timestamptz
------------------------
 2026-11-17 09:00:00+00

# SELECT '2026-11-17 10:00 Europe/Berlin'::timestamptz;

      timestamptz
------------------------
 2026-11-17 09:00:00+00

However, with timetz:

# SELECT '10:00 CET'::timetz;

   timetz
-------------
 10:00:00+01
(1 row)

I would expect 09:00:00+00 rather than 10:00:00+01, as the session time zone is set to UTC.

Best regards,

miracee (Susanne)






Re: Inconsistent time zone handling in timetz

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
miracee  writes:
> # SELECT '10:00 CET'::timetz;

>    timetz
> -------------
>  10:00:00+01
> (1 row)

> # SELECT '10:00 Europe/Berlin'::timetz;

> ERROR: invalid input syntax for type time with time zone: "10:00 Europe/Berlin"
> LINE 1: SELECT '10:00 Europe/Berlin'::timetz;

This is documented, no? [1]

    ... You can also specify a date but it will be ignored, except when
    you use a time zone name that involves a daylight-savings rule,
    such as America/New_York. In this case specifying the date is
    required in order to determine whether standard or
    daylight-savings time applies. The appropriate time zone offset is
    recorded in the time with time zone value and is output as stored;
    it is not adjusted to the active time zone.

I'd agree that the error message is pretty nonspecific :-(.  However,
the view this project takes is that timetz is a type with little if
any real-world use, so we're unlikely to put much effort into making
it more user-friendly.

			regards, tom lane

[1] https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-DATETIME-INPUT-TIMES


FAQ