pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6231: weird to_timestamp behaviour with out of range values
5+ messages / 4 participants
[nested] [flat]

* BUG #6231: weird to_timestamp behaviour with out of range values
@ 2011-09-28 14:55  Henk Enting <h.d.enting@mgrid.net>
  0 siblings, 1 reply; 5+ messages in thread

From: Henk Enting @ 2011-09-28 14:55 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      6231
Logged by:          Henk Enting
Email address:      h.d.enting@mgrid.net
PostgreSQL version: 9.1.1
Operating system:   linux x86_64
Description:        weird to_timestamp behaviour with out of range values
Details: 

I would expect the to_timestamp function to return an error when I feed it
out of range values, e.g. months > 13 and days > 31. Instead it seems to add
the surplus to the timestamp and then return it.

E.g. 21-21 becomes sept. 22th the next year.

psql output:

postgres=# select to_timestamp('2011-21-21', 'YYYY-MM-DD');
      to_timestamp      
------------------------
 2012-09-22 00:00:00+02
(1 row)

postgres=# select to_timestamp('2011-21-42', 'YYYY-MM-DD');
      to_timestamp      
------------------------
 2012-10-13 00:00:00+02
(1 row)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6231: weird to_timestamp behaviour with out of range values
@ 2011-09-28 15:43  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Henk Enting <h.d.enting@mgrid.net>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2011-09-28 15:43 UTC (permalink / raw)
  To: Henk Enting <h.d.enting@mgrid.net>; +Cc: pgsql-bugs

"Henk Enting" <h.d.enting@mgrid.net> writes:
> I would expect the to_timestamp function to return an error when I feed it
> out of range values, e.g. months > 13 and days > 31. Instead it seems to add
> the surplus to the timestamp and then return it.

What is your reason for using to_timestamp at all?  The timestamp input
converter is perfectly capable of dealing with standard formats like
yyyy-mm-dd, and it does what most people expect in the way of data
validation checks.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6231: weird to_timestamp behaviour with out of range values
@ 2011-09-29 15:39  Robert Haas <robertmhaas@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Robert Haas @ 2011-09-29 15:39 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Henk Enting <h.d.enting@mgrid.net>; pgsql-bugs

On Wed, Sep 28, 2011 at 11:43 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Henk Enting" <h.d.enting@mgrid.net> writes:
>> I would expect the to_timestamp function to return an error when I feed it
>> out of range values, e.g. months > 13 and days > 31. Instead it seems to add
>> the surplus to the timestamp and then return it.
>
> What is your reason for using to_timestamp at all?  The timestamp input
> converter is perfectly capable of dealing with standard formats like
> yyyy-mm-dd, and it does what most people expect in the way of data
> validation checks.

Well, you might want to insist that the input is in some particular
format, rather than just "whatever the input function will accept"...

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6231: weird to_timestamp behaviour with out of range values
@ 2011-09-30 08:43  Henk Enting <h.d.enting@mgrid.net>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Henk Enting @ 2011-09-30 08:43 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs

On Thu, Sep 29, 2011 at 5:39 PM, Robert Haas <robertmhaas@gmail.com> wrote:

> On Wed, Sep 28, 2011 at 11:43 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > "Henk Enting" <h.d.enting@mgrid.net> writes:
> >> I would expect the to_timestamp function to return an error when I feed
> it
> >> out of range values, e.g. months > 13 and days > 31. Instead it seems to
> add
> >> the surplus to the timestamp and then return it.
> >
> > What is your reason for using to_timestamp at all?  The timestamp input
> > converter is perfectly capable of dealing with standard formats like
> > yyyy-mm-dd, and it does what most people expect in the way of data
> > validation checks.
>
> Well, you might want to insist that the input is in some particular
> format, rather than just "whatever the input function will accept"...
>
Exactly. But I probably can rely on the input function and set the datastyle
parameter to make sure I get the right dates (e.g. in our case 07-04-2011is
in april, not in july).
But still, I think the to_timestamp should throw an error if I put in
something like '21-21-2011'.

Best Regards,

Henk Enting

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6231: weird to_timestamp behaviour with out of range values
@ 2011-10-02 00:00  Stephen Frost <sfrost@snowman.net>
  parent: Henk Enting <h.d.enting@mgrid.net>
  0 siblings, 0 replies; 5+ messages in thread

From: Stephen Frost @ 2011-10-02 00:00 UTC (permalink / raw)
  To: Henk Enting <h.d.enting@mgrid.net>; +Cc: Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs

* Henk Enting (h.d.enting@mgrid.net) wrote:
> But still, I think the to_timestamp should throw an error if I put in
> something like '21-21-2011'.

I agree completely, this is a pretty big bug in my opinion.  We don't
accept invalid or garbage timestamps in the input function, I don't see
any reason why we should be allowing it in to_timestamp().  If the
values at the 'MM' location are outside of the valid range, we should be
throwing an error.

	Thanks,

		Stephen

Attachments:

  signature.asc (application/pgp-signature, 197B) download

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2011-10-02 00:00 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-28 14:55 BUG #6231: weird to_timestamp behaviour with out of range values Henk Enting <h.d.enting@mgrid.net>
2011-09-28 15:43 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-09-29 15:39   ` Robert Haas <robertmhaas@gmail.com>
2011-09-30 08:43     ` Henk Enting <h.d.enting@mgrid.net>
2011-10-02 00:00       ` Stephen Frost <sfrost@snowman.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox