From: Tom Lane <tgl@sss.pgh.pa.us>
To: 正华吕 <kainwen@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Question on cast string to date
Date: Tue, 10 May 2022 00:44:43 -0400
Message-ID: <4035765.1652157883@sss.pgh.pa.us> (raw)
In-Reply-To: <CANerzAcbEw0Uvv9APGK4FORGbeJ0ftwtuG6=kNgA_P0NTxa9ew@mail.gmail.com>
References: <CANerzAcbEw0Uvv9APGK4FORGbeJ0ftwtuG6=kNgA_P0NTxa9ew@mail.gmail.com>
=?UTF-8?B?5q2j5Y2O5ZCV?= <kainwen@gmail.com> writes:
> I test the following SQL in pg15dev (seems same behavior as the
> previous version).
> select '2020701'::date;
> date
> ------------
> 0202-07-01
> (1 row)
> At the first glance, the result seems quite strange.
[ shrug... ] You left out a zero. It's not apparent to me that
this answer is wrong.
> The question here is: should we throw error for such input? Or what
> standard postgres is
> using to cast such kind of string?
The bar to changing any behavior here is a *lot* higher than
you seem to imagine.
Having said that, it does appear that we changed this somewhere
between 9.3 and 9.4:
psql (9.3.25)
Type "help" for help.
regression=# select '2020701'::date;
ERROR: invalid input syntax for type date: "2020701"
LINE 1: select '2020701'::date;
^
psql (9.4.26)
Type "help" for help.
regression=# select '2020701'::date;
date
------------
0202-07-01
(1 row)
If you want to pursue this question, you could start by bisecting
to find just which commit changed it and why.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, kainwen@gmail.com
Subject: Re: Question on cast string to date
In-Reply-To: <4035765.1652157883@sss.pgh.pa.us>
References: <CANerzAcbEw0Uvv9APGK4FORGbeJ0ftwtuG6=kNgA_P0NTxa9ew@mail.gmail.com> <4035765.1652157883@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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