Re: Constructors for dates, times, and timestamps - Mailing list pgsql-general

From Tom Lane
Subject Re: Constructors for dates, times, and timestamps
Date
Msg-id 25227.1172767085@sss.pgh.pa.us
Whole thread Raw
In response to Constructors for dates, times, and timestamps  ("Andrew T. Robinson" <atr@nmi.net>)
Responses Re: Constructors for dates, times, and timestamps  ("Andrew T. Robinson" <atr@nmi.net>)
List 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 by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: supporting 2000 simultaneous connections.
Next
From: "Jan Muszynski"
Date:
Subject: ftell mismatch with expected position