DATE type output does not follow datestyle parameter

Started by MauMauover 12 years ago9 messages
#1MauMau
maumau307@gmail.com

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Bruce Momjian
bruce@momjian.us
In reply to: MauMau (#1)
Re: DATE type output does not follow datestyle parameter

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@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Robert Haas
robertmhaas@gmail.com
In reply to: Bruce Momjian (#2)
Re: DATE type output does not follow datestyle parameter

On Tue, Aug 6, 2013 at 11:40 AM, Bruce Momjian <bruce@momjian.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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#2)
Re: DATE type output does not follow datestyle parameter

Bruce Momjian <bruce@momjian.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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#4)
Re: DATE type output does not follow datestyle parameter

On Tue, Aug 6, 2013 at 12:09:53PM -0400, Tom Lane wrote:

Bruce Momjian <bruce@momjian.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@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6MauMau
maumau307@gmail.com
In reply to: Bruce Momjian (#5)
Re: DATE type output does not follow datestyle parameter

Hi, Bruce san,

From: "Bruce Momjian" <bruce@momjian.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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Bruce Momjian
bruce@momjian.us
In reply to: MauMau (#6)
Re: DATE type output does not follow datestyle parameter

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@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#8MauMau
maumau307@gmail.com
In reply to: Bruce Momjian (#7)
Re: DATE type output does not follow datestyle parameter

From: "Bruce Momjian" <bruce@momjian.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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Bruce Momjian
bruce@momjian.us
In reply to: MauMau (#8)
1 attachment(s)
Re: DATE type output does not follow datestyle parameter

On Wed, Feb 12, 2014 at 10:08:26PM +0900, MauMau wrote:

From: "Bruce Momjian" <bruce@momjian.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@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachments:

datestyle.difftext/x-diff; charset=us-asciiDownload
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
new file mode 100644
index b7d7d80..30fd9bb
*** a/doc/src/sgml/datatype.sgml
--- b/doc/src/sgml/datatype.sgml
*************** January 8 04:05:06 1999 PST
*** 2205,2212 ****
       historical accident.)  <xref
       linkend="datatype-datetime-output-table"> shows examples of each
       output style.  The output of the <type>date</type> and
!      <type>time</type> types is of course only the date or time part
!      in accordance with the given examples.
      </para>
  
       <table id="datatype-datetime-output-table">
--- 2205,2214 ----
       historical accident.)  <xref
       linkend="datatype-datetime-output-table"> shows examples of each
       output style.  The output of the <type>date</type> and
!      <type>time</type> types is generally only the date or time part
!      in accordance with the given examples.  However, the
!      <productname>POSTGRES</> style outputs date-only values in
!      <acronym>ISO</acronym> format.
      </para>
  
       <table id="datatype-datetime-output-table">