Re: Constructors for dates, times, and timestamps

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Andrew T(dot) Robinson" <atr(at)nmi(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Constructors for dates, times, and timestamps
Date: 2007-03-01 16:39:59
Message-ID: 20070301163959.GB1705@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Feb 27, 2007 at 07:47:32AM -0500, Andrew T. Robinson wrote:
> Migrating from DB/2 6.1 to PostgreSQL 8.1.4,
>
> 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()?]

Well, you can always use to_timestamp and then cast to time, but this
also works:

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

I can't explain the need for the quotes, some kind of grammer issue.

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

There is the function datetime_pl(date,time) whic does that, but most
people just use +'

# select '2007-05-02'::date + '22:33:44'::time;
?column?
---------------------
2007-05-02 22:33:44
(1 row)

You can wrap it into a simple function if that makes it easier to
understand.

Oddly, the documentation indeed doesn't list all the functions, but the
operators will do what you want also.

http://www.postgresql.org/docs/current/static/functions-datetime.html

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message George Nychis 2007-03-01 16:40:11 get username of user calling function?
Previous Message A. Kretschmer 2007-03-01 16:39:39 Re: creating a function with a variable table name