Re: DATE type output does not follow datestyle parameter

Lists: pgsql-hackers
From: "MauMau" <maumau307(at)gmail(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: DATE type output does not follow datestyle parameter
Date: 2013-07-24 12:06:30
Message-ID: 6E6F9C9777FC4FAC9ECC6E1348513DD7@maumau
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello,

The description of datestyle parameter does not seem to match the actual
behavior. Is this a bug to be fixed? Which do you think should be
corrected, the program or the manual?

The manual says:

DateStyle (string)
Sets the display format for date and time values, as well as the rules for
interpreting ambiguous date input values. For historical reasons, this
variable contains two independent components: the output format
specification (ISO, Postgres, SQL, or German) and the input/output
specification for year/month/day ordering (DMY, MDY, or YMD). ...

And says:

http://www.postgresql.org/docs/current/static/datatype-datetime.html

8.5.2. Date/Time Output
The output of the date and time types is of course only the date or time
part in accordance with the given examples.

After doing "SET datestyle = 'Postgres, MDY'" on the psql prompt, I did the
following things on the same psql session:

1. SELECT current_timestamp;

now
----------------------------------
Wed Jul 24 10:51:00.217 2013 GMT
(1 行)

This is exactly as I expected.

2. SELECT current_date;
I expected the output "Wed Jul 24 2013" or "Jul 24 2013", but I got:

date
------------
07-24-2013
(1 行)

This does not follow the above statement in 8.5.2. This output is created
by EncodeDateOnly() in src/backend/utils/adt/datetime.c.

Regards
MauMau


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: MauMau <maumau307(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2013-08-06 15:40:51
Message-ID: 20130806154051.GR11189@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jul 24, 2013 at 09:06:30PM +0900, MauMau wrote:
> Hello,
>
> The description of datestyle parameter does not seem to match the
> actual behavior. Is this a bug to be fixed? Which do you think
> should be corrected, the program or the manual?
>
>
> The manual says:
>
> DateStyle (string)
> Sets the display format for date and time values, as well as the
> rules for interpreting ambiguous date input values. For historical
> reasons, this variable contains two independent components: the
> output format specification (ISO, Postgres, SQL, or German) and the
> input/output specification for year/month/day ordering (DMY, MDY, or
> YMD). ...
>
>
> And says:
>
> http://www.postgresql.org/docs/current/static/datatype-datetime.html
>
> 8.5.2. Date/Time Output
> The output of the date and time types is of course only the date or
> time part in accordance with the given examples.
>
>
> After doing "SET datestyle = 'Postgres, MDY'" on the psql prompt, I
> did the following things on the same psql session:
>
>
> 1. SELECT current_timestamp;
>
> now
> ----------------------------------
> Wed Jul 24 10:51:00.217 2013 GMT
> (1 行)
>
> This is exactly as I expected.
>
>
> 2. SELECT current_date;
> I expected the output "Wed Jul 24 2013" or "Jul 24 2013", but I got:
>
> date
> ------------
> 07-24-2013
> (1 行)
>
> This does not follow the above statement in 8.5.2. This output is
> created by EncodeDateOnly() in src/backend/utils/adt/datetime.c.

Yes, you are correct, this is inconsistent. Let me look at writing a
patch to fix this. Is this format so old that we can't fix this?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: MauMau <maumau307(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2013-08-06 15:52:58
Message-ID: CA+TgmoaWPmJ+LnEpaPaa+q8sgMK1QZeDLrbKfo3VBmZBjbGwtg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Aug 6, 2013 at 11:40 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Yes, you are correct, this is inconsistent. Let me look at writing a
> patch to fix this. Is this format so old that we can't fix this?

I think I would be more inclined to change the documentation than the behavior.

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: MauMau <maumau307(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2013-08-06 16:09:53
Message-ID: 30133.1375805393@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Is this format so old that we can't fix this?

Yes. I don't see any reason to change it, either, as nobody has
complained that it's actually bad. If you feel a compulsion to
change the docs, do that.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: MauMau <maumau307(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2013-08-06 20:42:12
Message-ID: 20130806204211.GW11189@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Aug 6, 2013 at 12:09:53PM -0400, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Is this format so old that we can't fix this?
>
> Yes. I don't see any reason to change it, either, as nobody has
> complained that it's actually bad. If you feel a compulsion to
> change the docs, do that.

OK, seems 'Postgres' is a unique output format for 'date' too, even though
it doesn't look like the 'Postgres' timestamp output:

default
SET datestyle = 'ISO, MDY'; SELECT current_timestamp, current_date;
SET
now | date
-------------------------------+------------
2013-08-06 16:18:48.218555-04 | 2013-08-06

SET datestyle = 'SQL, MDY'; SELECT current_timestamp, current_date;
SET
now | date
--------------------------------+------------
08/06/2013 16:18:43.054488 EDT | 08/06/2013

SET datestyle = 'German, MDY'; SELECT current_timestamp, current_date;
SET
now | date
--------------------------------+------------
06.08.2013 16:18:59.026553 EDT | 06.08.2013

MDY
SET datestyle = 'Postgres, MDY'; SELECT current_timestamp, current_date;
SET
now | date
-------------------------------------+------------
Tue Aug 06 16:18:53.590548 2013 EDT | 08-06-2013

DMY
SET datestyle = 'Postgres, DMY'; SELECT current_timestamp, current_date;
SET
now | date
-------------------------------------+------------
Tue 06 Aug 16:20:23.902549 2013 EDT | 06-08-2013

I don't think there is even a documentation change I can suggest.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: "MauMau" <maumau307(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2013-12-02 13:22:47
Message-ID: 2598E90D3D534989905115C5C1172679@maumau
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi, Bruce san,

From: "Bruce Momjian" <bruce(at)momjian(dot)us>
> On Tue, Aug 6, 2013 at 12:09:53PM -0400, Tom Lane wrote:
>> Yes. I don't see any reason to change it, either, as nobody has
>> complained that it's actually bad. If you feel a compulsion to
>> change the docs, do that.
>
> OK, seems 'Postgres' is a unique output format for 'date' too, even though
> it doesn't look like the 'Postgres' timestamp output:
>
> default
> SET datestyle = 'ISO, MDY'; SELECT current_timestamp, current_date;
> SET
> now | date
> -------------------------------+------------
> 2013-08-06 16:18:48.218555-04 | 2013-08-06
>
> SET datestyle = 'SQL, MDY'; SELECT current_timestamp, current_date;
> SET
> now | date
> --------------------------------+------------
> 08/06/2013 16:18:43.054488 EDT | 08/06/2013
>
> SET datestyle = 'German, MDY'; SELECT current_timestamp, current_date;
> SET
> now | date
> --------------------------------+------------
> 06.08.2013 16:18:59.026553 EDT | 06.08.2013
>
> MDY
> SET datestyle = 'Postgres, MDY'; SELECT current_timestamp, current_date;
> SET
> now | date
> -------------------------------------+------------
> Tue Aug 06 16:18:53.590548 2013 EDT | 08-06-2013
>
> DMY
> SET datestyle = 'Postgres, DMY'; SELECT current_timestamp, current_date;
> SET
> now | date
> -------------------------------------+------------
> Tue 06 Aug 16:20:23.902549 2013 EDT | 06-08-2013
>
> I don't think there is even a documentation change I can suggest.

I'm sorry I didn't respond for a long time. I've come up with a suggestion.

The original reporter of this problem expected the output of the date type
in 'Postgres,DMY' style to be "17 Dec 1997", when the output of the
timestamp if "Wed 17 Dec 07:37:16 1997 PST". He thought so by reading the
following sentence:

http://www.postgresql.org/docs/current/static/datatype-datetime.html
The output of the date and time types is of course only the date or time
part in accordance with the given examples.

However, the actual output of the date type in Postgres style is:

* 12-17-1997 if datestyle is 'Postgres,YMD' or 'Postgres,MDY'
* 17-12-1997 if datestyle is 'Postgres,DMY'

So, my suggestion is to just add the following sentence right after the
above one.

The Postgres style is an exception: the output of the date type is either
MM-DD-YYYY (e.g. 12-17-1997) or DD-MM-YYYY (e.g. 17-12-1997), which is
different from the date part of the output of the timestamp type.

Could you consider and add this to the manual?

Regards
MauMau


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: MauMau <maumau307(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2013-12-02 16:52:43
Message-ID: 20131202165243.GD5274@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Dec 2, 2013 at 10:22:47PM +0900, MauMau wrote:
> I'm sorry I didn't respond for a long time. I've come up with a suggestion.
>
> The original reporter of this problem expected the output of the
> date type in 'Postgres,DMY' style to be "17 Dec 1997", when the
> output of the timestamp if "Wed 17 Dec 07:37:16 1997 PST". He
> thought so by reading the following sentence:
>
> http://www.postgresql.org/docs/current/static/datatype-datetime.html
> The output of the date and time types is of course only the date or
> time part in accordance with the given examples.
>
> However, the actual output of the date type in Postgres style is:
>
> * 12-17-1997 if datestyle is 'Postgres,YMD' or 'Postgres,MDY'
> * 17-12-1997 if datestyle is 'Postgres,DMY'
>
> So, my suggestion is to just add the following sentence right after
> the above one.
>
> The Postgres style is an exception: the output of the date type is
> either MM-DD-YYYY (e.g. 12-17-1997) or DD-MM-YYYY (e.g. 17-12-1997),
> which is different from the date part of the output of the timestamp
> type.
>
> Could you consider and add this to the manual?

Yes, I will make the change unless someone objects.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +


From: "MauMau" <maumau307(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2014-02-12 13:08:26
Message-ID: 7AB998D4A4074791B86ED175808639E3@maumau
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

From: "Bruce Momjian" <bruce(at)momjian(dot)us>
> On Mon, Dec 2, 2013 at 10:22:47PM +0900, MauMau wrote:
>> So, my suggestion is to just add the following sentence right after
>> the above one.
>>
>> The Postgres style is an exception: the output of the date type is
>> either MM-DD-YYYY (e.g. 12-17-1997) or DD-MM-YYYY (e.g. 17-12-1997),
>> which is different from the date part of the output of the timestamp
>> type.
>>
>> Could you consider and add this to the manual?
>
> Yes, I will make the change unless someone objects.

Could you commit this if you feel okay? I'm sorry if I missed the modified
article in the devel doc.

Regards
MauMau


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: MauMau <maumau307(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: DATE type output does not follow datestyle parameter
Date: 2014-02-12 16:25:31
Message-ID: 20140212162531.GC12551@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Feb 12, 2014 at 10:08:26PM +0900, MauMau wrote:
> From: "Bruce Momjian" <bruce(at)momjian(dot)us>
> >On Mon, Dec 2, 2013 at 10:22:47PM +0900, MauMau wrote:
> >>So, my suggestion is to just add the following sentence right after
> >>the above one.
> >>
> >>The Postgres style is an exception: the output of the date type is
> >>either MM-DD-YYYY (e.g. 12-17-1997) or DD-MM-YYYY (e.g. 17-12-1997),
> >>which is different from the date part of the output of the timestamp
> >>type.
> >>
> >>Could you consider and add this to the manual?
> >
> >Yes, I will make the change unless someone objects.
>
> Could you commit this if you feel okay? I'm sorry if I missed the
> modified article in the devel doc.

OK, attached doc patch applied to head and 9.3. Thanks for the report.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachment Content-Type Size
datestyle.diff text/x-diff 1.1 KB