Re: Unpredictable text -> date implicit casting behaviour/to_date bug

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
Subject: Re: Unpredictable text -> date implicit casting behaviour/to_date bug
Date: 2001-12-31 16:02:47
Message-ID: 12926.1009814567@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches pgsql-sql

"Aasmund Midttun Godal" <postgresql(at)envisity(dot)com> writes:
> The implicit casting of text to date is normally quite good, however i
> think it should only use one method during a given query (or maybe
> transaction?)

Try setting DateStyle to match the date style you are using. Postgres
is doing the best it can with ambiguous input.

> Added to the fact that to_date has a bug:

> SELECT ordredato, ordredato::date, to_date(ordredato, 'DD.MM.YY') from old_faktura where status = 'ANN';
> ordredato | ?column? | to_date
> -----------+------------+---------------
> 18.04.00 | 2000-04-18 | 0001-04-18 BC
> 30.08.01 | 2001-08-30 | 2001-08-30
> 18.04.00 | 2000-04-18 | 0001-04-18 BC

I agree, this is not desired behavior. The problem seems to be that the
logic in to_timestamp() tries to use "field is not zero" as a substitute
test for "field was provided". At least in the case of the year fields,
this is *not* workable. There must be a separate flag bit.

regards, tom lane

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Brent Verner 2002-01-01 23:01:52 Re: [PATCHES] system catalog relation of a table and a serial sequence
Previous Message Aasmund Midttun Godal 2001-12-31 14:38:15 Unpredictable text -> date implicit casting behaviour/to_date bug

Browse pgsql-sql by date

  From Date Subject
Next Message Shamik Majumder 2002-01-01 11:51:12 Need help
Previous Message Aasmund Midttun Godal 2001-12-31 14:38:15 Unpredictable text -> date implicit casting behaviour/to_date bug