Re: to_date() not works as described for pattern DD & HH

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Rhode <Andreas(dot)Rhode(at)gmx(dot)de>
Cc: pgsql-bugs(at)postgresql(dot)org, "Rhode,A(dot),SNL IT BRIEF,2520,DA, Berater" <andreas(dot)rhode(at)deutschepost(dot)de>
Subject: Re: to_date() not works as described for pattern DD & HH
Date: 2015-12-18 15:43:42
Message-ID: 6847.1450453422@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Andreas Rhode <Andreas(dot)Rhode(at)gmx(dot)de> writes:
> The 2 Pattern DD/HH are not well working
> All Digs ar counted from Position6/8 are counted as Days or Hour
> and produce a future Date or error from a Timestamp in Milliseconds

As far as I can see, the problem here is that you're not giving a pattern
that accurately describes the input data.

> SELECT to_date('20151202115909001','YYYYMMDD') AS der_2_december_eleven_a_clock
> -> "5795177-12-29 => fare away in the future

A correct format for this input would be something like YYYYMMDDHH24MISSMS:

# SELECT to_timestamp('20151202115909001','YYYYMMDDHH24MISSMS');
to_timestamp
----------------------------
2015-12-02 11:59:09.001-05
(1 row)

I think what is happening in your example is that it's including all the
remaining adjacent digits in the DD field. While this seems silly here,
it's less silly in, for example,

# SELECT to_date('201512021','YYYYMMDD');
to_date
------------
2015-12-21
(1 row)

But it's not really to_date's job to parse input that is not correctly
described by the given format.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2015-12-18 16:22:12 Re: Known issues on PostgreSQL server 8.1.19
Previous Message Millepied, Pascal (GE Healthcare) 2015-12-18 15:33:57 Re: Known issues on PostgreSQL server 8.1.19