Re: Constructors for dates, times, and timestamps

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Constructors for dates, times, and timestamps
Дата
Msg-id 25227.1172767085@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Constructors for dates, times, and timestamps  ("Andrew T. Robinson" <atr@nmi.net>)
Ответы Re: Constructors for dates, times, and timestamps  ("Andrew T. Robinson" <atr@nmi.net>)
Список pgsql-general
"Andrew T. Robinson" <atr@nmi.net> writes:
> The following work under DB/2, but I can find no analog in the
> PostgreSQL documentation:

>     time('00:00:00')  [there is to_date() and to_timestamp(), but no
> to_time()?]

Write it as a cast, either SQL-spec CAST() or PG :: notation.

regression=# select '00:00:00'::time;
   time
----------
 00:00:00
(1 row)

In many situations PG also accepts the same function-like notation for
specifying casts that DB/2 seems to be using, but in this particular
case it doesn't work because TIME(n) is a datatype specification
according to the SQL spec, and the special syntax needed for that
conflicts with this usage.

>     timestamp(u.date, u.time) [where u.date is of type DATE and u.time
> is of type TIME]

You can add a date and a time to get a timestamp:

regression=# select '3-1-2007'::date + '12:34'::time;
      ?column?
---------------------
 2007-03-01 12:34:00
(1 row)

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: supporting 2000 simultaneous connections.
Следующее
От: "Jan Muszynski"
Дата:
Сообщение: ftell mismatch with expected position