Обсуждение: DATE type output does not follow datestyle parameter

Поиск
Список
Период
Сортировка

DATE type output does not follow datestyle parameter

От
"MauMau"
Дата:
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 OutputThe 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




Re: DATE type output does not follow datestyle parameter

От
Bruce Momjian
Дата:
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. +



Re: DATE type output does not follow datestyle parameter

От
Robert Haas
Дата:
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



Re: DATE type output does not follow datestyle parameter

От
Tom Lane
Дата:
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



Re: DATE type output does not follow datestyle parameter

От
Bruce Momjian
Дата:
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-06SET datestyle = 'SQL, MDY';
SELECTcurrent_timestamp, current_date;SET              now               |
date--------------------------------+------------08/06/2013 16:18:43.054488 EDT | 08/06/2013SET 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. +




Re: DATE type output does not follow datestyle parameter

От
"MauMau"
Дата:
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






Re: DATE type output does not follow datestyle parameter

От
Bruce Momjian
Дата:
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. +



Re: DATE type output does not follow datestyle parameter

От
"MauMau"
Дата:
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




Re: DATE type output does not follow datestyle parameter

От
Bruce Momjian
Дата:
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. +

Вложения