pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUnpredictable text -> date implicit casting behaviour/to_date bug
5+ messages / 4 participants
[nested] [flat]
* Unpredictable text -> date implicit casting behaviour/to_date bug
@ 2001-12-31 14:38 Aasmund Midttun Godal <postgresql@envisity.com>
2001-12-31 16:02 ` Re: Unpredictable text -> date implicit casting behaviour/to_date bug Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Aasmund Midttun Godal @ 2001-12-31 14:38 UTC (permalink / raw)
To: pgsql-sql
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?) or maybe it should give a notice of some sort? - i was quite astonished when I discovered the following: (look closely at row 4 and 5 vs the others)
SELECT ordredato, ordredato::date from old_faktura where status = 'ORD';
ordredato | ?column?
-----------+------------
18.10.01 | 2001-10-18
31.10.01 | 2001-10-31
01.11.01 | 2001-01-11
03.11.01 | 2001-03-11
03.11.01 | 2001-03-11
10.11.01 | 2001-10-11
26.11.01 | 2001-11-26
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
It sometimes makes converting dates a little challenge...
Aasmund Midttun Godal
aasmund@godal.com - http://www.godal.com/
+47 40 45 20 46
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Unpredictable text -> date implicit casting behaviour/to_date bug
2001-12-31 14:38 Unpredictable text -> date implicit casting behaviour/to_date bug Aasmund Midttun Godal <postgresql@envisity.com>
@ 2001-12-31 16:02 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-01-02 13:04 ` Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date bug Karel Zak <zakkr@zf.jcu.cz>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2001-12-31 16:02 UTC (permalink / raw)
To: Aasmund Midttun Godal <postgresql@envisity.com>; +Cc: pgsql-sql@postgresql.org, Karel Zak <zakkr@zf.jcu.cz>
"Aasmund Midttun Godal" <postgresql@envisity.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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date bug
2001-12-31 14:38 Unpredictable text -> date implicit casting behaviour/to_date bug Aasmund Midttun Godal <postgresql@envisity.com>
2001-12-31 16:02 ` Re: Unpredictable text -> date implicit casting behaviour/to_date bug Tom Lane <tgl@sss.pgh.pa.us>
@ 2002-01-02 13:04 ` Karel Zak <zakkr@zf.jcu.cz>
2002-01-02 18:26 ` Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date Bruce Momjian <pgman@candle.pha.pa.us>
2002-01-02 22:10 ` Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date bug Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 5+ messages in thread
From: Karel Zak @ 2002-01-02 13:04 UTC (permalink / raw)
To: pgsql-patches <pgsql-patches@postgreSQL.org>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Aasmund Midttun Godal <postgresql@envisity.com>
On Mon, Dec 31, 2001 at 11:02:47AM -0500, Tom Lane wrote:
> "Aasmund Midttun Godal" <postgresql@envisity.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
Nice bug :-(
It's fixed and the patch is attached, please apply it to 7.2.
Thanks for report.
Karel
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
Attachments:
formatting-01022002.patch.gz (application/x-gzip, 1.1K) download
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date
2001-12-31 14:38 Unpredictable text -> date implicit casting behaviour/to_date bug Aasmund Midttun Godal <postgresql@envisity.com>
2001-12-31 16:02 ` Re: Unpredictable text -> date implicit casting behaviour/to_date bug Tom Lane <tgl@sss.pgh.pa.us>
2002-01-02 13:04 ` Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date bug Karel Zak <zakkr@zf.jcu.cz>
@ 2002-01-02 18:26 ` Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 0 replies; 5+ messages in thread
From: Bruce Momjian @ 2002-01-02 18:26 UTC (permalink / raw)
To: Karel Zak <zakkr@zf.jcu.cz>; +Cc: pgsql-patches <pgsql-patches@postgresql.org>; Tom Lane <tgl@sss.pgh.pa.us>; Aasmund Midttun Godal <postgresql@envisity.com>
Thomas added datetime stuff over the weekend, so I assume this patch
should be applied in the next 24 hours, unless someone objects.
---------------------------------------------------------------------------
Karel Zak wrote:
> On Mon, Dec 31, 2001 at 11:02:47AM -0500, Tom Lane wrote:
> > "Aasmund Midttun Godal" <postgresql@envisity.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
>
> Nice bug :-(
>
> It's fixed and the patch is attached, please apply it to 7.2.
>
> Thanks for report.
>
> Karel
>
> --
> Karel Zak <zakkr@zf.jcu.cz>
> http://home.zf.jcu.cz/~zakkr/
>
> C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
[ Attachment, skipping... ]
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date bug
2001-12-31 14:38 Unpredictable text -> date implicit casting behaviour/to_date bug Aasmund Midttun Godal <postgresql@envisity.com>
2001-12-31 16:02 ` Re: Unpredictable text -> date implicit casting behaviour/to_date bug Tom Lane <tgl@sss.pgh.pa.us>
2002-01-02 13:04 ` Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date bug Karel Zak <zakkr@zf.jcu.cz>
@ 2002-01-02 22:10 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 5+ messages in thread
From: Tom Lane @ 2002-01-02 22:10 UTC (permalink / raw)
To: Karel Zak <zakkr@zf.jcu.cz>; +Cc: pgsql-patches <pgsql-patches@postgreSQL.org>; Aasmund Midttun Godal <postgresql@envisity.com>
Karel Zak <zakkr@zf.jcu.cz> writes:
> It's fixed and the patch is attached, please apply it to 7.2.
Patch applied to CVS. Thanks!
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2002-01-02 22:10 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-12-31 14:38 Unpredictable text -> date implicit casting behaviour/to_date bug Aasmund Midttun Godal <postgresql@envisity.com>
2001-12-31 16:02 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-01-02 13:04 ` Karel Zak <zakkr@zf.jcu.cz>
2002-01-02 18:26 ` Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date Bruce Momjian <pgman@candle.pha.pa.us>
2002-01-02 22:10 ` Tom Lane <tgl@sss.pgh.pa.us>
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