Re: to_timestamp() too loose?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: to_timestamp() too loose?
Date: 2012-08-23 13:42:18
Message-ID: 10579.1345729338@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Magnus Hagander <magnus(at)hagander(dot)net> writes:
> postgres=# select to_timestamp('2012-08-01', 'yyyy-mm-dd');
> to_timestamp
> ------------------------
> 2012-08-01 00:00:00+02

> postgres=# select to_timestamp('2012-08-00', 'yyyy-mm-dd');
> to_timestamp
> ------------------------
> 2012-08-01 00:00:00+02

> postgres=# select to_timestamp('2012-00-00', 'yyyy-mm-dd');
> to_timestamp
> ------------------------
> 2012-01-01 00:00:00+01

> Should we really convert 00 to 01?

to_timestamp is intentionally pretty loose. Personally, if I wanted
sanity checking on a date string in any common format, I would just
cast the string to timestamp(tz), and *not* use to_timestamp.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2012-08-23 13:44:04 Re: to_timestamp() too loose?
Previous Message Tom Lane 2012-08-23 13:36:23 Re: new --maintenance-db options