Apply (a somewhat revised version of) Greg Mullane's patch to eliminate
authorTom Lane
Tue, 29 Jul 2003 00:03:19 +0000 (00:03 +0000)
committerTom Lane
Tue, 29 Jul 2003 00:03:19 +0000 (00:03 +0000)
heuristic determination of day vs month in date/time input.  Add the
ability to specify that input is interpreted as yy-mm-dd order (which
formerly worked, but only for yy greater than 31).  DateStyle's input
component now has the preferred spellings DMY, MDY, or YMD; the older
keywords European and US are now aliases for the first two of these.
Per recent discussions on pgsql-general.

26 files changed:
doc/src/sgml/datatype.sgml
doc/src/sgml/datetime.sgml
doc/src/sgml/func.sgml
doc/src/sgml/ref/postgres-ref.sgml
doc/src/sgml/ref/set.sgml
doc/src/sgml/ref/show.sgml
doc/src/sgml/release.sgml
doc/src/sgml/runtime.sgml
src/backend/commands/variable.c
src/backend/tcop/postgres.c
src/backend/utils/adt/datetime.c
src/backend/utils/init/globals.c
src/backend/utils/misc/README
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/bin/psql/tab-complete.c
src/include/miscadmin.h
src/test/regress/expected/horology-no-DST-before-1970.out
src/test/regress/expected/horology-solaris-1947.out
src/test/regress/expected/horology.out
src/test/regress/expected/timestamp.out
src/test/regress/expected/timestamptz.out
src/test/regress/pg_regress.sh
src/test/regress/sql/horology.sql
src/test/regress/sql/timestamp.sql
src/test/regress/sql/timestamptz.sql

index 348e1427735fe2dbf80224962762224074703b15..fd81d447fd092c3797673dabced6de996d856364 100644 (file)
@@ -1,5 +1,5 @@
 
 
  
@@ -1346,15 +1346,12 @@ SELECT b, char_length(b) FROM test2;
      Date and time input is accepted in almost any reasonable format, including
      ISO 8601, SQL-compatible, 
      traditional POSTGRES, and others.
-     For some formats, ordering of month and day in date input can be
+     For some formats, ordering of month, day, and year in date input is
      ambiguous and there is support for specifying the expected
-     ordering of these fields.
-     The command
-     SET datestyle TO 'US' 
-     or SET datestyle TO 'NonEuropean'
-     specifies the variant month before day, the command
-     SET datestyle TO 'European' sets the variant
-     day before month.
+     ordering of these fields.  Set the datestyle parameter
+     to MDY to select month-day-year interpretation,
+     DMY to select day-month-year interpretation, or
+     YMD to select year-month-day interpretation.
     
 
     
@@ -1410,36 +1407,42 @@ SELECT b, char_length(b) FROM test2;
        
    
     January 8, 1999
-    unambiguous
+    unambiguous in any datestyle input mode
    
    
     1999-01-08
-    ISO-8601 format, preferred
+    ISO-8601, January 8 in any mode
+    (recommended format)
    
    
     1/8/1999
-    ambiguous (January 8 in U.S. mode; August 1 in European mode)
+    January 8 in MDY mode;
+     August 1 in DMY mode
    
    
     1/18/1999
-    U.S. notation; January 18 in any mode
+    January 18 in MDY mode;
+     rejected in other modes
+   
+   
+    01/02/03
+    January 2, 2003 in MDY mode;
+     February 1, 2003 in DMY mode;
+     February 3, 2001 in YMD mode
+    
    
    
     19990108
-    ISO-8601; year, month, day
+    ISO-8601; January 8, 1999 in any mode
    
    
     990108
-    ISO-8601; year, month, day
+    ISO-8601; January 8, 1999 in any mode
    
    
     1999.008
     year and day of year
    
-   
-    99008
-    year and day of year
-   
    
     J2451187
     Julian day
@@ -1480,7 +1483,8 @@ SELECT b, char_length(b) FROM test2;
      
       Valid input for these types consists of a time of day followed
       by an optional time zone. (See 
-      linkend="datatype-datetime-time-table">.)  If a time zone is
+      linkend="datatype-datetime-time-table"> 
+      and .)  If a time zone is
       specified in the input for time without time zone,
       it is silently ignored.
      
@@ -1539,14 +1543,43 @@ SELECT b, char_length(b) FROM test2;
     040506-08
     ISO 8601
    
+   
+    04:05:06 PST
+    timezone specified by name
+   
        
       
      
 
-     
-      Refer to  for
-      more examples of time zones.
-     
+      
+       Time Zone Input
+       
+   
+    
+     Example
+     Description
+    
+   
+   
+    
+     PST
+     Pacific Standard Time
+    
+    
+     -8:00
+     ISO-8601 offset for PST
+    
+    
+     -800
+     ISO-8601 offset for PST
+    
+    
+     -8
+     ISO-8601 offset for PST
+    
+   
+       
+      
     
 
     
@@ -1571,8 +1604,7 @@ SELECT b, char_length(b) FROM test2;
       Valid input for the time stamp types consists of a concatenation
       of a date and a time, followed by an optional
       AD or BC, followed by an
-      optional time zone. (See 
-      linkend="datatype-timezone-table">.)  Thus
+      optional time zone. Thus
 
 
 1999-01-08 04:05:06
@@ -1626,36 +1658,6 @@ January 8 04:05:06 1999 PST
       as timezone local time.  A different zone reference can
       be specified for the conversion using AT TIME ZONE.
      
-
-      
-       Time Zone Input
-       
-   
-    
-     Example
-     Description
-    
-   
-   
-    
-     PST
-     Pacific Standard Time
-    
-    
-     -8:00
-     ISO-8601 offset for PST
-    
-    
-     -800
-     ISO-8601 offset for PST
-    
-    
-     -8
-     ISO-8601 offset for PST
-    
-   
-       
-      
     
 
     
@@ -1760,7 +1762,7 @@ January 8 04:05:06 1999 PST
     
      now
           datetimetimestamp
-     current transaction time
+     current transaction's start time
     
     
      today
@@ -1805,9 +1807,10 @@ January 8 04:05:06 1999 PST
     
 
     
-     The output format of the date/time types can be set to one of the four styles ISO 8601,
+     The output format of the date/time types can be set to one of the four
+     styles ISO 8601,
      SQL (Ingres), traditional POSTGRES, and
-     German, using the SET datestyle.  The default
+     German, using the command SET datestyle.  The default
      is the ISO format.  (The
      SQL standard requires the use of the ISO 8601
      format.  The name of the SQL output format is a
@@ -1854,9 +1857,10 @@ January 8 04:05:06 1999 PST
      
 
     
-     The SQL style has European and non-European
-     (U.S.) variants, which determines whether month follows day or
-     vice versa. (See 
+     In the SQL and POSTGRES styles, day appears before
+     month if DMY field ordering has been specified, otherwise month appears
+     before day.
+     (See 
      for how this setting also affects interpretation of input values.)
       shows an
      example.
@@ -1867,22 +1871,27 @@ January 8 04:05:06 1999 PST
       
        
    
-    Style Specification
-    Description
-    Example
+    DateStyle setting
+    Input Ordering
+    Example Output
    
        
        
    
-    European
+    SQL, DMY
     day/month/year
     17/12/1997 15:37:16.00 CET
    
    
-    US
+    SQL, MDY
     month/day/year
     12/17/1997 07:37:16.00 PST
    
+   
+    Postgres, DMY
+    day/month/year
+    Wed 17 Dec 07:37:16 1997 PST
+   
        
       
      
@@ -1903,7 +1912,7 @@ January 8 04:05:06 1999 PST
      The date/time styles can be selected by the user using the
      SET datestyle command, the
      datestyle parameter in the
-     postgresql.conf configuration file, and the
+     postgresql.conf configuration file, or the
      PGDATESTYLE environment variable on the server or
      client.  The formatting function to_char
      (see ) is also available as
index d7a76dab2331d17e123f6bdce2c30bb5d1b03a44..c205ee9c31448cfb8fdcaf68849e3c5b39804328 100644 (file)
@@ -1,5 +1,5 @@
 
 
  
@@ -27,7 +27,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datetime.sgml,v 2.31 2003/04/07 01:29:25 pe
    Date/Time Input Interpretation
 
    
-    The date/time type inputs are all decoded using the following routine.
+    The date/time type inputs are all decoded using the following procedure.
    
 
    
@@ -103,7 +103,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datetime.sgml,v 2.31 2003/04/07 01:29:25 pe
 
       
        
-   If not found, throw an error.
+   If still not found, throw an error.
        
       
      
@@ -111,70 +111,47 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datetime.sgml,v 2.31 2003/04/07 01:29:25 pe
     
     
      
-      The token is a number or number field.
+      When the token is a number or number field:
      
 
      
       
        
-   If there are more than 4 digits, 
+   If there are eight or six digits,
    and if no other date fields have been previously read, then interpret 
-   as a concatenated date (e.g., 19990118). 8
-   and 6 digits are interpreted as year, month, and day, while 7
-   and 5 digits are interpreted as year, day of year, respectively.
+   as a concatenated date (e.g.,
+   19990118 or 990118).
+   The interpretation is YYYYMMDD or YYMMDD.
        
       
 
       
        
    If the token is three digits
-   and a year has already been decoded, then interpret as day of year.
+   and a year has already been read, then interpret as day of year.
        
       
       
       
        
    If four or six digits and a year has already been read, then
-   interpret as a time.
+   interpret as a time (HHMM or HHMMSS).
        
       
 
       
        
-   If four or more digits, then interpret as a year.
+   If three or more digits and no date fields have yet been found,
+   interpret as a year (this forces yy-mm-dd ordering of the remaining
+   date fields).
        
       
 
       
        
-   If in European date mode, and if the day field has not yet been read,
-   and if the value is less than or equal to 31, then interpret as a day.
-       
-      
-
-      
-       
-   If the month field has not yet been read,
-   and if the value is less than or equal to 12, then interpret as a month.
-       
-      
-
-      
-       
-   If the day field has not yet been read,
-   and if the value is less than or equal to 31, then interpret as a day.
-       
-      
-
-      
-       
-   If two digits or four or more digits, then interpret as a year.
-       
-      
-
-      
-       
-   Otherwise, throw an error.
+        Otherwise the date field ordering is assumed to follow the
+   DateStyle setting: mm-dd-yy, dd-mm-yy, or yy-mm-dd.
+   Throw an error if a month or day field is found to be out of range.
        
       
      
index 942bd83c782c51cdee4782d8109e0d38af2c4201..d5a528e1c381a6a469abfbaab3e61b9bb345c6ab 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -6503,7 +6503,7 @@ SELECT current_setting('datestyle');
 
  current_setting
 -----------------
- ISO, US
+ ISO, MDY
 (1 row)
 
    
index e09c523b1ab2b236b3ef30a62040a72b40ed803c..073b83fd7d979f2f0c9baee75ca913113d337b9e 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -147,11 +147,10 @@ PostgreSQL documentation
       
       
        
-        Sets the default date style to European, which
-   means that the day before month (rather than
-   month before day) rule is used to interpret ambiguous date
-   input, and that the day is printed before the month in certain
-   date output formats.  See  for more information.
+        Sets the default date style to European, that is
+   DMY ordering of input date fields.  This also causes
+   the day to be printed before the month in certain date output formats.
+   See  for more information.
        
       
      
index 08ea5f3c2f4b18e3c01657805ea4dde84ecdc3b1..bb1ddd227599794e6c5364288e633e58dcb3f441 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -283,9 +283,10 @@ SET search_path TO my_schema, public;
 
   
    Set the style of date to traditional
-   POSTGRES with European conventions:
+   POSTGRES with day before month
+   input convention:
 
-SET datestyle TO postgres,european;
+SET datestyle TO postgres, dmy;
 
   
 
index 1302ee2661ac887263801046cd9e84d6bdf8c6a2..1f0f52735a0c5aec32e7c4b625720cd32f411429 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -158,7 +158,7 @@ SHOW ALL
 SHOW DateStyle;
  DateStyle
 -----------
- ISO, US
+ ISO, MDY
 (1 row)
 
   
index 4bca26e8fd16d09553012a32b28d11bfe0d81e32..50e42336d4ec2cf63bc163824abe5746ba47e83e 100644 (file)
@@ -1,5 +1,5 @@
 
 
 
@@ -26,6 +26,8 @@ worries about funny characters.
 
 EXTRACT(TIMEZONE) and SET/SHOW TIMEZONE now follow SQL sign convention
   (positive = east of UTC)
+DATESTYLE can now be set to DMY, YMD, or MDY to specify input field order
+Input date order must now be YYYY-MM-DD (with 4-digit year) or match DATESTYLE
 Output of SHOW DATESTYLE is now in the same format accepted by SET DATESTYLE
 PL/Python is now an untrusted language, and is renamed to 'plpythonu'
 Dollar sign ($) is no longer allowed in operator names
index d5598cd0b967674bf91a6bc1708ae41a2b2e2c68..43b8204389044e8950d28ccd88a232a498df603b 100644 (file)
@@ -1,5 +1,5 @@
 
 
 
@@ -2101,9 +2101,17 @@ SET ENABLE_SEQSCAN TO OFF;
       
        
         Sets the display format for date and time values, as well as
-        the rules for interpreting ambiguous date input values.  See
-         for more information.  The
-        default is ISO, US.
+        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 date field order specification (DMY, MDY,
+   or YMD).  These can be set separately or together.
+   The keywords Euro and European are synonyms
+   for DMY; the keywords US, NonEuro,
+   and NonEuropean are synonyms for MDY.
+   See  for more information.  The
+        default is ISO, MDY.
        
       
      
index a9fc94adc3d2145fd598f4252ff04c70ea27bf2a..e0b041636e6f3965a7378e8cd44c95509dddaa07 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.84 2003/07/28 00:09:14 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.85 2003/07/29 00:03:18 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -51,10 +51,10 @@ const char *
 assign_datestyle(const char *value, bool doit, bool interactive)
 {
    int         newDateStyle = DateStyle;
-   bool        newEuroDates = EuroDates;
+   int         newDateOrder = DateOrder;
    bool        ok = true;
-   int         dcnt = 0,
-               ecnt = 0;
+   int         scnt = 0,
+               ocnt = 0;
    char       *rawstring;
    char       *result;
    List       *elemlist;
@@ -85,38 +85,43 @@ assign_datestyle(const char *value, bool doit, bool interactive)
        if (strcasecmp(tok, "ISO") == 0)
        {
            newDateStyle = USE_ISO_DATES;
-           dcnt++;
+           scnt++;
        }
        else if (strcasecmp(tok, "SQL") == 0)
        {
            newDateStyle = USE_SQL_DATES;
-           dcnt++;
+           scnt++;
        }
        else if (strncasecmp(tok, "POSTGRES", 8) == 0)
        {
            newDateStyle = USE_POSTGRES_DATES;
-           dcnt++;
+           scnt++;
        }
        else if (strcasecmp(tok, "GERMAN") == 0)
        {
            newDateStyle = USE_GERMAN_DATES;
-           dcnt++;
-           if ((ecnt > 0) && (!newEuroDates))
-               ok = false;
-           newEuroDates = TRUE;
+           scnt++;
+           /* GERMAN also sets DMY, unless explicitly overridden */
+           if (ocnt == 0)
+               newDateOrder = DATEORDER_DMY;
        }
-       else if (strncasecmp(tok, "EURO", 4) == 0)
+       else if (strcasecmp(tok, "YMD") == 0)
        {
-           newEuroDates = TRUE;
-           ecnt++;
+           newDateOrder = DATEORDER_YMD;
+           ocnt++;
        }
-       else if (strcasecmp(tok, "US") == 0
-                || strncasecmp(tok, "NONEURO", 7) == 0)
+       else if (strcasecmp(tok, "DMY") == 0 ||
+                strncasecmp(tok, "EURO", 4) == 0)
        {
-           newEuroDates = FALSE;
-           ecnt++;
-           if ((dcnt > 0) && (newDateStyle == USE_GERMAN_DATES))
-               ok = false;
+           newDateOrder = DATEORDER_DMY;
+           ocnt++;
+       }
+       else if (strcasecmp(tok, "MDY") == 0 ||
+                strcasecmp(tok, "US") == 0 ||
+                strncasecmp(tok, "NONEURO", 7) == 0)
+       {
+           newDateOrder = DATEORDER_MDY;
+           ocnt++;
        }
        else if (strcasecmp(tok, "DEFAULT") == 0)
        {
@@ -128,15 +133,17 @@ assign_datestyle(const char *value, bool doit, bool interactive)
             * to handle constructs like "DEFAULT, ISO".
             */
            int         saveDateStyle = DateStyle;
-           bool        saveEuroDates = EuroDates;
+           int         saveDateOrder = DateOrder;
            const char *subval;
 
            subval = assign_datestyle(GetConfigOptionResetString("datestyle"),
                                      true, interactive);
-           newDateStyle = DateStyle;
-           newEuroDates = EuroDates;
+           if (scnt == 0)
+               newDateStyle = DateStyle;
+           if (ocnt == 0)
+               newDateOrder = DateOrder;
            DateStyle = saveDateStyle;
-           EuroDates = saveEuroDates;
+           DateOrder = saveDateOrder;
            if (!subval)
            {
                ok = false;
@@ -145,8 +152,6 @@ assign_datestyle(const char *value, bool doit, bool interactive)
            /* Here we know that our own return value is always malloc'd */
            /* when doit is true */
            free((char *) subval);
-           dcnt++;
-           ecnt++;
        }
        else
        {
@@ -160,7 +165,7 @@ assign_datestyle(const char *value, bool doit, bool interactive)
        }
    }
 
-   if (dcnt > 1 || ecnt > 1)
+   if (scnt > 1 || ocnt > 1)
        ok = false;
 
    pfree(rawstring);
@@ -203,14 +208,25 @@ assign_datestyle(const char *value, bool doit, bool interactive)
            strcpy(result, "Postgres");
            break;
    }
-   strcat(result, newEuroDates ? ", European" : ", US");
+   switch (newDateOrder)
+   {
+       case DATEORDER_YMD:
+           strcat(result, ", YMD");
+           break;
+       case DATEORDER_DMY:
+           strcat(result, ", DMY");
+           break;
+       default:
+           strcat(result, ", MDY");
+           break;
+   }
 
    /*
     * Finally, it's safe to assign to the global variables; the
     * assignment cannot fail now.
     */
    DateStyle = newDateStyle;
-   EuroDates = newEuroDates;
+   DateOrder = newDateOrder;
 
    return result;
 }
index 9b2324b220f9fc31e048b7e461dc57bbab6f917e..80f2be70ed643d1ab39b3c1f85c355c5ae069815 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.352 2003/07/27 21:49:54 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.353 2003/07/29 00:03:18 tgl Exp $
  *
  * NOTES
  *   this is the "main" module of the postgres backend and
@@ -1958,7 +1958,7 @@ usage(char *progname)
    printf("  -c NAME=VALUE   set run-time parameter\n");
    printf("  -d 0-5          debugging level (0 is off)\n");
    printf("  -D DATADIR      database directory\n");
-   printf("  -e              use European date format\n");
+   printf("  -e              use European date input format (DMY)\n");
    printf("  -E              echo query before execution\n");
    printf("  -F              turn fsync off\n");
    printf("  -N              do not use newline as interactive query delimiter\n");
@@ -2155,7 +2155,7 @@ PostgresMain(int argc, char *argv[], const char *username)
            case 'e':
 
                /*
-                * Use european date formats.
+                * Use European date input format (DMY)
                 */
                SetConfigOption("datestyle", "euro", ctx, gucsource);
                break;
@@ -2626,7 +2626,7 @@ PostgresMain(int argc, char *argv[], const char *username)
    if (!IsUnderPostmaster)
    {
        puts("\nPOSTGRES backend interactive interface ");
-       puts("$Revision: 1.352 $ $Date: 2003/07/27 21:49:54 $\n");
+       puts("$Revision: 1.353 $ $Date: 2003/07/29 00:03:18 $\n");
    }
 
    /*
index 1b9b4fcc821f16ee050c00d32e0578ee13b34f92..f053c9ebb2c121380dcc52667459605044df4236 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.107 2003/07/27 04:53:04 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.108 2003/07/29 00:03:18 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1425,23 +1425,47 @@ DecodeDateTime(char **field, int *ftype, int nf,
        fmask |= tmask;
    }
 
-   /* there is no year zero in AD/BC notation; i.e. "1 BC" == year 0 */
-   if (bc)
+   if (fmask & DTK_M(YEAR))
    {
-       if (tm->tm_year > 0)
-           tm->tm_year = -(tm->tm_year - 1);
-       else
-           ereport(ERROR,
-                   (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
-                    errmsg("inconsistent use of year %04d and \"BC\"",
-                           tm->tm_year)));
+       /* there is no year zero in AD/BC notation; i.e. "1 BC" == year 0 */
+       if (bc)
+       {
+           if (tm->tm_year > 0)
+               tm->tm_year = -(tm->tm_year - 1);
+           else
+               ereport(ERROR,
+                       (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
+                        errmsg("inconsistent use of year %04d and \"BC\"",
+                               tm->tm_year)));
+       }
+       else if (is2digits)
+       {
+           if (tm->tm_year < 70)
+               tm->tm_year += 2000;
+           else if (tm->tm_year < 100)
+               tm->tm_year += 1900;
+       }
    }
-   else if (is2digits)
+
+   /* now that we have correct year, decode DOY */
+   if (fmask & DTK_M(DOY))
    {
-       if (tm->tm_year < 70)
-           tm->tm_year += 2000;
-       else if (tm->tm_year < 100)
-           tm->tm_year += 1900;
+       j2date(date2j(tm->tm_year, 1, 1) + tm->tm_yday - 1,
+              &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
+   }
+
+   /* check for valid month */
+   if (fmask & DTK_M(MONTH))
+   {
+       if (tm->tm_mon < 1 || tm->tm_mon > 12)
+           return -1;
+   }
+
+   /* minimal check for valid day */
+   if (fmask & DTK_M(DAY))
+   {
+       if (tm->tm_mday < 1 || tm->tm_mday > 31)
+           return -1;
    }
 
    if ((mer != HR24) && (tm->tm_hour > 12))
@@ -1461,13 +1485,11 @@ DecodeDateTime(char **field, int *ftype, int nf,
         * check for valid day of month, now that we know for sure the
         * month and year...
         */
-       if ((tm->tm_mday < 1)
-        || (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]))
+       if (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
            return -1;
 
        /* timezone not specified? then find local timezone if possible */
-       if (((fmask & DTK_DATE_M) == DTK_DATE_M)
-           && (tzp != NULL) && (!(fmask & DTK_M(TZ))))
+       if ((tzp != NULL) && (!(fmask & DTK_M(TZ))))
        {
            /*
             * daylight savings time modifier but no standard timezone?
@@ -2259,6 +2281,22 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
            tm->tm_year += 1900;
    }
 
+   /* now that we have correct year, decode DOY */
+   if (fmask & DTK_M(DOY))
+   {
+       j2date(date2j(tm->tm_year, 1, 1) + tm->tm_yday - 1,
+              &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
+   }
+
+   /* check for valid month */
+   if (tm->tm_mon < 1 || tm->tm_mon > 12)
+       return -1;
+
+   /* check for valid day */
+   if (tm->tm_mday < 1 ||
+       tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
+       return -1;
+
    return 0;
 }  /* DecodeDate() */
 
@@ -2356,8 +2394,8 @@ DecodeNumber(int flen, char *str, int fmask,
    if (*cp == '.')
    {
        /*
-        * More than two digits? Then could be a date or a run-together
-        * time: 2001.360 20011225 040506.789
+        * More than two digits before decimal point? Then could be a date
+        * or a run-together time: 2001.360 20011225 040506.789
         */
        if ((cp - str) > 2)
            return DecodeNumberField(flen, str, (fmask | DTK_DATE_M),
@@ -2370,85 +2408,91 @@ DecodeNumber(int flen, char *str, int fmask,
    else if (*cp != '\0')
        return -1;
 
-   /* Special case day of year? */
-   if ((flen == 3) && (fmask & DTK_M(YEAR))
-       && ((val >= 1) && (val <= 366)))
+   /* Special case for day of year */
+   if ((flen == 3) &&
+       ((fmask & DTK_DATE_M) == DTK_M(YEAR)) &&
+       ((val >= 1) && (val <= 366)))
    {
        *tmask = (DTK_M(DOY) | DTK_M(MONTH) | DTK_M(DAY));
        tm->tm_yday = val;
-       j2date(date2j(tm->tm_year, 1, 1) + tm->tm_yday - 1,
-              &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
+       /* tm_mon and tm_mday can't actually be set yet ... */
+       return 0;
    }
 
-   /***
-    * Enough digits to be unequivocal year? Used to test for 4 digits or
-    * more, but we now test first for a three-digit doy so anything
-    * bigger than two digits had better be an explicit year.
-    * - thomas 1999-01-09
-    * Back to requiring a 4 digit year. We accept a two digit
-    * year farther down. - thomas 2000-03-28
-    ***/
-   else if (flen >= 4)
+   /* Switch based on what we have so far */
+   switch (fmask & DTK_DATE_M)
    {
-       *tmask = DTK_M(YEAR);
+       case 0:
+           /*
+            * Nothing so far; make a decision about what we think the
+            * input is.  There used to be lots of heuristics here, but
+            * the consensus now is to be paranoid.  It *must* be either
+            * YYYY-MM-DD (with a more-than-two-digit year field), or the
+            * field order defined by DateOrder.
+            */
+           if (flen >= 3 || DateOrder == DATEORDER_YMD)
+           {
+               *tmask = DTK_M(YEAR);
+               tm->tm_year = val;
+           }
+           else if (DateOrder == DATEORDER_DMY)
+           {
+               *tmask = DTK_M(DAY);
+               tm->tm_mday = val;
+           }
+           else
+           {
+               *tmask = DTK_M(MONTH);
+               tm->tm_mon = val;
+           }
+           break;
 
-       /* already have a year? then see if we can substitute... */
-       if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(DAY)))
-           && ((tm->tm_year >= 1) && (tm->tm_year <= 31)))
-       {
-           tm->tm_mday = tm->tm_year;
+       case (DTK_M(YEAR)):
+           /* Must be at second field of YY-MM-DD */
+           *tmask = DTK_M(MONTH);
+           tm->tm_mon = val;
+           break;
+
+       case (DTK_M(YEAR) | DTK_M(MONTH)):
+           /* Must be at third field of YY-MM-DD */
            *tmask = DTK_M(DAY);
-       }
+           tm->tm_mday = val;
+           break;
 
-       tm->tm_year = val;
-   }
+       case (DTK_M(DAY)):
+           /* Must be at second field of DD-MM-YY */
+           *tmask = DTK_M(MONTH);
+           tm->tm_mon = val;
+           break;
 
-   /* already have year? then could be month */
-   else if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(MONTH)))
-            && ((val >= 1) && (val <= 12)))
-   {
-       *tmask = DTK_M(MONTH);
-       tm->tm_mon = val;
-   }
-   /* no year and EuroDates enabled? then could be day */
-   else if ((EuroDates || (fmask & DTK_M(MONTH)))
-            && (!(fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY)))
-            && ((val >= 1) && (val <= 31)))
-   {
-       *tmask = DTK_M(DAY);
-       tm->tm_mday = val;
-   }
-   else if ((!(fmask & DTK_M(MONTH)))
-            && ((val >= 1) && (val <= 12)))
-   {
-       *tmask = DTK_M(MONTH);
-       tm->tm_mon = val;
-   }
-   else if ((!(fmask & DTK_M(DAY)))
-            && ((val >= 1) && (val <= 31)))
-   {
-       *tmask = DTK_M(DAY);
-       tm->tm_mday = val;
+       case (DTK_M(MONTH) | DTK_M(DAY)):
+           /* Must be at third field of DD-MM-YY or MM-DD-YY */
+           *tmask = DTK_M(YEAR);
+           tm->tm_year = val;
+           break;
+
+       case (DTK_M(MONTH)):
+           /* Must be at second field of MM-DD-YY */
+           *tmask = DTK_M(DAY);
+           tm->tm_mday = val;
+           break;
+
+       default:
+           /* Anything else is bogus input */
+           return -1;
    }
 
    /*
-    * Check for 2 or 4 or more digits, but currently we reach here only
-    * if two digits. - thomas 2000-03-28
+    * When processing a year field, mark it for adjustment if it's
+    * exactly two digits.
     */
-   else if (!(fmask & DTK_M(YEAR))
-            && ((flen >= 4) || (flen == 2)))
+   if (*tmask == DTK_M(YEAR))
    {
-       *tmask = DTK_M(YEAR);
-       tm->tm_year = val;
-
-       /* adjust ONLY if exactly two digits... */
        *is2digits = (flen == 2);
    }
-   else
-       return -1;
 
    return 0;
-}  /* DecodeNumber() */
+}
 
 
 /* DecodeNumberField()
@@ -2512,18 +2556,6 @@ DecodeNumberField(int len, char *str, int fmask,
            tm->tm_year = atoi(str + 0);
            *is2digits = TRUE;
 
-           return DTK_DATE;
-       }
-       /* yyddd? */
-       else if (len == 5)
-       {
-           *tmask = DTK_DATE_M;
-           tm->tm_mday = atoi(str + 2);
-           *(str + 2) = '\0';
-           tm->tm_mon = 1;
-           tm->tm_year = atoi(str + 0);
-           *is2digits = TRUE;
-
            return DTK_DATE;
        }
    }
@@ -3152,7 +3184,7 @@ EncodeDateOnly(struct tm * tm, int style, char *str)
 
        case USE_SQL_DATES:
            /* compatible with Oracle/Ingres date formats */
-           if (EuroDates)
+           if (DateOrder == DATEORDER_DMY)
                sprintf(str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
            else
                sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
@@ -3174,7 +3206,7 @@ EncodeDateOnly(struct tm * tm, int style, char *str)
        case USE_POSTGRES_DATES:
        default:
            /* traditional date-only style for Postgres */
-           if (EuroDates)
+           if (DateOrder == DATEORDER_DMY)
                sprintf(str, "%02d-%02d", tm->tm_mday, tm->tm_mon);
            else
                sprintf(str, "%02d-%02d", tm->tm_mon, tm->tm_mday);
@@ -3308,7 +3340,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
        case USE_SQL_DATES:
            /* Compatible with Oracle/Ingres date formats */
 
-           if (EuroDates)
+           if (DateOrder == DATEORDER_DMY)
                sprintf(str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
            else
                sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
@@ -3410,7 +3442,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
            strncpy(str, days[tm->tm_wday], 3);
            strcpy((str + 3), " ");
 
-           if (EuroDates)
+           if (DateOrder == DATEORDER_DMY)
                sprintf((str + 4), "%02d %3s", tm->tm_mday, months[tm->tm_mon - 1]);
            else
                sprintf((str + 4), "%3s %02d", months[tm->tm_mon - 1], tm->tm_mday);
index 2a7a372fa6dc5b7ca353c279ae3b0acb9e17cc4b..6e6551f10190f58e70422491926b38a40124fc61 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.72 2003/06/27 14:45:30 petere Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.73 2003/07/29 00:03:18 tgl Exp $
  *
  * NOTES
  *   Globals used all over the place should be declared here and not
@@ -62,7 +62,7 @@ bool      IsUnderPostmaster = false;
 bool       ExitOnAnyError = false;
 
 int            DateStyle = USE_ISO_DATES;
-bool       EuroDates = false;
+int            DateOrder = DATEORDER_MDY;
 bool       HasCTZSet = false;
 int            CTimeZone = 0;
 
index fe252d534deddf4e144c2ee807270695377ee67a..b8610a97b8eab8c2126226d5a82e518c6b752ff7 100644 (file)
@@ -1,4 +1,4 @@
-$Header: /cvsroot/pgsql/src/backend/utils/misc/README,v 1.1 2002/05/17 01:19:18 tgl Exp $
+$Header: /cvsroot/pgsql/src/backend/utils/misc/README,v 1.2 2003/07/29 00:03:18 tgl Exp $
 
 
 GUC IMPLEMENTATION NOTES
@@ -49,8 +49,8 @@ variables, but the return value is handled differently:
    malloc'd (not palloc'd!!!) string --- assign that value instead
 The third choice is allowed in case the assign_hook wants to return a
 "canonical" version of the new value.  For example, the assign_hook for
-datestyle always returns a string that includes both basic datestyle and
-us/euro option, although the input might have specified only one.
+datestyle always returns a string that includes both output and input
+datestyle options, although the input might have specified only one.
 
 If a show_hook is provided, it points to a function of the signature
    const char *show_hook(void)
index d6ed9ba462675926a975ca9c4bd9d46bcc7c6460..a7eb4f5ed169b149d3004cf06819fa97dd8e8737 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut .
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.143 2003/07/28 19:31:32 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.144 2003/07/29 00:03:18 tgl Exp $
  *
  *--------------------------------------------------------------------
  */
@@ -1338,13 +1338,13 @@ static struct config_string ConfigureNamesString[] =
 
    {
        {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
-           gettext_noop("The display format for date and time values"),
-           gettext_noop("As well as the rules for interpreting ambiguous date "
-                        "input values"),
+           gettext_noop("The display format for date and time values"),
+           gettext_noop("as well as the rules for interpreting ambiguous "
+                        "date input values"),
            GUC_LIST_INPUT | GUC_REPORT
        },
        &datestyle_string,
-       "ISO, US", assign_datestyle, NULL
+       "ISO, MDY", assign_datestyle, NULL
    },
 
    {
index 584e24f42879104ab0ae61f8e4c3e4d1677310d8..6ed1aae20813359bd469944945189f7bbe12e231 100644 (file)
 
 # - Locale and Formatting -
 
-#datestyle = 'iso, us'
+#datestyle = 'iso, mdy'
 #timezone = unknown        # actually, defaults to TZ environment setting
 #australian_timezones = false
 #extra_float_digits = 0        # min -15, max 2
index 8f70c25e761dccc16874268686cadcb765b25337..a7e9fbca3d4d8fa2661b8bb932d7e981acc5c05c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000-2002 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.81 2003/06/30 16:47:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.82 2003/07/29 00:03:18 tgl Exp $
  */
 
 /*----------------------------------------------------------------------
@@ -1187,8 +1187,10 @@ psql_completion(char *text, int start, int end)
    {
        if (strcasecmp(prev2_wd, "DateStyle") == 0)
        {
-           char       *my_list[] = {"'ISO'", "'SQL'", "'Postgres'",
-           "'European'", "'NonEuropean'", "'German'", "DEFAULT", NULL};
+           char       *my_list[] = {"ISO", "SQL", "Postgres", "German",
+                                    "YMD", "DMY", "MDY",
+                                    "US", "European", "NonEuropean",
+                                    "DEFAULT", NULL};
 
            COMPLETE_WITH_LIST(my_list);
        }
index 5fee7fc25f94d6d20de26e90b913bd6e964a8b55..7e7219ef4dc34cd95558edad15cd6e0026f405e4 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: miscadmin.h,v 1.128 2003/07/27 21:49:54 tgl Exp $
+ * $Id: miscadmin.h,v 1.129 2003/07/29 00:03:18 tgl Exp $
  *
  * NOTES
  *   some of the information in this file should be moved to
@@ -135,35 +135,53 @@ extern char pg_pathname[];
  */
 extern DLLIMPORT Oid MyDatabaseId;
 
-/* Date/Time Configuration
+/*
+ * Date/Time Configuration
  *
- * Constants to pass info from runtime environment:
- * USE_POSTGRES_DATES specifies traditional postgres format for output.
- * USE_ISO_DATES specifies ISO-compliant format for output.
- * USE_SQL_DATES specified Oracle/Ingres-compliant format for output.
- * USE_GERMAN_DATES specifies German-style dd.mm/yyyy date format.
+ * DateStyle defines the output formatting choice for date/time types:
+ * USE_POSTGRES_DATES specifies traditional Postgres format
+ * USE_ISO_DATES specifies ISO-compliant format
+ * USE_SQL_DATES specifies Oracle/Ingres-compliant format
+ * USE_GERMAN_DATES specifies German-style dd.mm/yyyy
  *
- * DateStyle specifies preference for date formatting for output.
- * EuroDates if client prefers dates interpreted and written w/European conventions.
+ * DateOrder defines the field order to be assumed when reading an
+ * ambiguous date (anything not in YYYY-MM-DD format, with a four-digit
+ * year field first, is taken to be ambiguous):
+ * DATEORDER_YMD specifies field order yy-mm-dd
+ * DATEORDER_DMY specifies field order dd-mm-yy ("European" convention)
+ * DATEORDER_MDY specifies field order mm-dd-yy ("US" convention)
  *
- * HasCTZSet is true if user has set timezone as a numeric offset from UTC.
- * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
- * sign convention, ie, positive offset is west of UTC, rather than the
- * SQL-ish convention that positive is east of UTC).
+ * In the Postgres and SQL DateStyles, DateOrder also selects output field
+ * order: day comes before month in DMY style, else month comes before day.
+ *
+ * The user-visible "DateStyle" run-time parameter subsumes both of these.
  */
 
-#define MAXTZLEN       10      /* max TZ name len, not counting tr. null */
-
+/* valid DateStyle values */
 #define USE_POSTGRES_DATES     0
 #define USE_ISO_DATES          1
 #define USE_SQL_DATES          2
 #define USE_GERMAN_DATES       3
 
+/* valid DateOrder values */
+#define DATEORDER_YMD          0
+#define DATEORDER_DMY          1
+#define DATEORDER_MDY          2
+
 extern int DateStyle;
-extern bool EuroDates;
+extern int DateOrder;
+
+/*
+ * HasCTZSet is true if user has set timezone as a numeric offset from UTC.
+ * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
+ * sign convention, ie, positive offset is west of UTC, rather than the
+ * SQL-ish convention that positive is east of UTC).
+ */
 extern bool HasCTZSet;
 extern int CTimeZone;
 
+#define MAXTZLEN       10      /* max TZ name len, not counting tr. null */
+
 extern bool enableFsync;
 extern bool allowSystemTableMods;
 extern DLLIMPORT int SortMem;
index f824122b8765b4d8965df0021d5c81332fdf7462..0aa1da407f461aa5fc1ef684cd96eac94c99ac16 100644 (file)
@@ -3,7 +3,7 @@
 --
 -- needed so tests pass even in Australia
 SET australian_timezones = 'off';
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 --
 -- Test various input formats
 --
@@ -79,12 +79,17 @@ SELECT timestamp with time zone '12/27/2001 04:05:06.789-08';
  Thu Dec 27 04:05:06.789 2001 PST
 (1 row)
 
+-- should fail in mdy mode:
+SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
+ERROR:  invalid input syntax for timestamp with time zone: "27/12/2001 04:05:06.789-08"
+set datestyle to dmy;
 SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
            timestamptz            
 ----------------------------------
- Thu Dec 27 04:05:06.789 2001 PST
+ Thu 27 Dec 04:05:06.789 2001 PST
 (1 row)
 
+reset datestyle;
 SELECT timestamp with time zone 'Y2001M12D27H04M05S06.789+08';
            timestamptz            
 ----------------------------------
@@ -170,13 +175,13 @@ SELECT timestamp with time zone 'J2452271T040506.789-08';
 (1 row)
 
 -- German/European-style dates with periods as delimiters
-SELECT timestamp with time zone '27.12.2001 04:05:06.789+08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789+08';
            timestamptz            
 ----------------------------------
  Wed Dec 26 12:05:06.789 2001 PST
 (1 row)
 
-SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789-08';
            timestamptz            
 ----------------------------------
  Thu Dec 27 04:05:06.789 2001 PST
@@ -257,7 +262,7 @@ SELECT time with time zone 'T040506.789 -08';
  04:05:06.7890-08
 (1 row)
 
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 --
 -- date, time arithmetic
 --
@@ -2385,9 +2390,9 @@ DROP TABLE TEMP_TIMESTAMP;
 --
 SET DateStyle TO 'US,Postgres';
 SHOW DateStyle;
-  DateStyle   
---------------
- Postgres, US
+   DateStyle   
+---------------
+ Postgres, MDY
 (1 row)
 
 SELECT '' AS "64", d1 AS us_postgres FROM TIMESTAMP_TBL;
@@ -2557,7 +2562,7 @@ SET DateStyle TO 'US,SQL';
 SHOW DateStyle;
  DateStyle 
 -----------
- SQL, US
+ SQL, MDY
 (1 row)
 
 SELECT '' AS "64", d1 AS us_sql FROM TIMESTAMP_TBL;
@@ -2643,9 +2648,9 @@ SELECT '' AS seven, f1 AS us_sql FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,Postgres';
 SHOW DateStyle;
-     DateStyle      
---------------------
- Postgres, European
+   DateStyle   
+---------------
+ Postgres, DMY
 (1 row)
 
 INSERT INTO TIMESTAMP_TBL VALUES('13/06/1957');
@@ -2739,9 +2744,9 @@ SELECT '' AS seven, f1 AS european_postgres FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,ISO';
 SHOW DateStyle;
-   DateStyle   
----------------
- ISO, European
+ DateStyle 
+-----------
+ ISO, DMY
 (1 row)
 
 SELECT '' AS "65", d1 AS european_iso FROM TIMESTAMP_TBL;
@@ -2828,9 +2833,9 @@ SELECT '' AS seven, f1 AS european_iso FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,SQL';
 SHOW DateStyle;
-   DateStyle   
----------------
- SQL, European
+ DateStyle 
+-----------
+ SQL, DMY
 (1 row)
 
 SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL;
index 736208001b56130219a0dce41a327e341a65e4ee..cdb9c7f1d867b29aac0d1cc3ac13d9db78b04fb0 100644 (file)
@@ -3,7 +3,7 @@
 --
 -- needed so tests pass even in Australia
 SET australian_timezones = 'off';
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 --
 -- Test various input formats
 --
@@ -79,12 +79,17 @@ SELECT timestamp with time zone '12/27/2001 04:05:06.789-08';
  Thu Dec 27 04:05:06.789 2001 PST
 (1 row)
 
+-- should fail in mdy mode:
+SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
+ERROR:  invalid input syntax for timestamp with time zone: "27/12/2001 04:05:06.789-08"
+set datestyle to dmy;
 SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
            timestamptz            
 ----------------------------------
- Thu Dec 27 04:05:06.789 2001 PST
+ Thu 27 Dec 04:05:06.789 2001 PST
 (1 row)
 
+reset datestyle;
 SELECT timestamp with time zone 'Y2001M12D27H04M05S06.789+08';
            timestamptz            
 ----------------------------------
@@ -170,13 +175,13 @@ SELECT timestamp with time zone 'J2452271T040506.789-08';
 (1 row)
 
 -- German/European-style dates with periods as delimiters
-SELECT timestamp with time zone '27.12.2001 04:05:06.789+08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789+08';
            timestamptz            
 ----------------------------------
  Wed Dec 26 12:05:06.789 2001 PST
 (1 row)
 
-SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789-08';
            timestamptz            
 ----------------------------------
  Thu Dec 27 04:05:06.789 2001 PST
@@ -257,7 +262,7 @@ SELECT time with time zone 'T040506.789 -08';
  04:05:06.7890-08
 (1 row)
 
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 --
 -- date, time arithmetic
 --
@@ -2385,9 +2390,9 @@ DROP TABLE TEMP_TIMESTAMP;
 --
 SET DateStyle TO 'US,Postgres';
 SHOW DateStyle;
-  DateStyle   
---------------
- Postgres, US
+   DateStyle   
+---------------
+ Postgres, MDY
 (1 row)
 
 SELECT '' AS "64", d1 AS us_postgres FROM TIMESTAMP_TBL;
@@ -2557,7 +2562,7 @@ SET DateStyle TO 'US,SQL';
 SHOW DateStyle;
  DateStyle 
 -----------
- SQL, US
+ SQL, MDY
 (1 row)
 
 SELECT '' AS "64", d1 AS us_sql FROM TIMESTAMP_TBL;
@@ -2643,9 +2648,9 @@ SELECT '' AS seven, f1 AS us_sql FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,Postgres';
 SHOW DateStyle;
-     DateStyle      
---------------------
- Postgres, European
+   DateStyle   
+---------------
+ Postgres, DMY
 (1 row)
 
 INSERT INTO TIMESTAMP_TBL VALUES('13/06/1957');
@@ -2739,9 +2744,9 @@ SELECT '' AS seven, f1 AS european_postgres FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,ISO';
 SHOW DateStyle;
-   DateStyle   
----------------
- ISO, European
+ DateStyle 
+-----------
+ ISO, DMY
 (1 row)
 
 SELECT '' AS "65", d1 AS european_iso FROM TIMESTAMP_TBL;
@@ -2828,9 +2833,9 @@ SELECT '' AS seven, f1 AS european_iso FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,SQL';
 SHOW DateStyle;
-   DateStyle   
----------------
- SQL, European
+ DateStyle 
+-----------
+ SQL, DMY
 (1 row)
 
 SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL;
index 735e703e4c4e1d28d27e176ae13907282b2c092c..984e75e8b4c6a97df9a4b1e1a1cc839748b3072b 100644 (file)
@@ -3,7 +3,7 @@
 --
 -- needed so tests pass even in Australia
 SET australian_timezones = 'off';
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 --
 -- Test various input formats
 --
@@ -79,12 +79,17 @@ SELECT timestamp with time zone '12/27/2001 04:05:06.789-08';
  Thu Dec 27 04:05:06.789 2001 PST
 (1 row)
 
+-- should fail in mdy mode:
+SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
+ERROR:  invalid input syntax for timestamp with time zone: "27/12/2001 04:05:06.789-08"
+set datestyle to dmy;
 SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
            timestamptz            
 ----------------------------------
- Thu Dec 27 04:05:06.789 2001 PST
+ Thu 27 Dec 04:05:06.789 2001 PST
 (1 row)
 
+reset datestyle;
 SELECT timestamp with time zone 'Y2001M12D27H04M05S06.789+08';
            timestamptz            
 ----------------------------------
@@ -170,13 +175,13 @@ SELECT timestamp with time zone 'J2452271T040506.789-08';
 (1 row)
 
 -- German/European-style dates with periods as delimiters
-SELECT timestamp with time zone '27.12.2001 04:05:06.789+08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789+08';
            timestamptz            
 ----------------------------------
  Wed Dec 26 12:05:06.789 2001 PST
 (1 row)
 
-SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789-08';
            timestamptz            
 ----------------------------------
  Thu Dec 27 04:05:06.789 2001 PST
@@ -257,7 +262,7 @@ SELECT time with time zone 'T040506.789 -08';
  04:05:06.7890-08
 (1 row)
 
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 --
 -- date, time arithmetic
 --
@@ -2385,9 +2390,9 @@ DROP TABLE TEMP_TIMESTAMP;
 --
 SET DateStyle TO 'US,Postgres';
 SHOW DateStyle;
-  DateStyle   
---------------
- Postgres, US
+   DateStyle   
+---------------
+ Postgres, MDY
 (1 row)
 
 SELECT '' AS "64", d1 AS us_postgres FROM TIMESTAMP_TBL;
@@ -2557,7 +2562,7 @@ SET DateStyle TO 'US,SQL';
 SHOW DateStyle;
  DateStyle 
 -----------
- SQL, US
+ SQL, MDY
 (1 row)
 
 SELECT '' AS "64", d1 AS us_sql FROM TIMESTAMP_TBL;
@@ -2643,9 +2648,9 @@ SELECT '' AS seven, f1 AS us_sql FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,Postgres';
 SHOW DateStyle;
-     DateStyle      
---------------------
- Postgres, European
+   DateStyle   
+---------------
+ Postgres, DMY
 (1 row)
 
 INSERT INTO TIMESTAMP_TBL VALUES('13/06/1957');
@@ -2739,9 +2744,9 @@ SELECT '' AS seven, f1 AS european_postgres FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,ISO';
 SHOW DateStyle;
-   DateStyle   
----------------
- ISO, European
+ DateStyle 
+-----------
+ ISO, DMY
 (1 row)
 
 SELECT '' AS "65", d1 AS european_iso FROM TIMESTAMP_TBL;
@@ -2828,9 +2833,9 @@ SELECT '' AS seven, f1 AS european_iso FROM ABSTIME_TBL;
 
 SET DateStyle TO 'European,SQL';
 SHOW DateStyle;
-   DateStyle   
----------------
- SQL, European
+ DateStyle 
+-----------
+ SQL, DMY
 (1 row)
 
 SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL;
index 71420dd2bafc0b621551e8e9163b8f2f32559042..0b45bb9c1a71f3c5544b6426e8b8b70251298b6b 100644 (file)
@@ -97,9 +97,11 @@ INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 PST');
 INSERT INTO TIMESTAMP_TBL VALUES ('Feb-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMP_TBL VALUES ('02-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 PST');
+set datestyle to ymd;
 INSERT INTO TIMESTAMP_TBL VALUES ('97FEB10 5:32:01PM UTC');
 INSERT INTO TIMESTAMP_TBL VALUES ('97/02/10 17:32:01 UTC');
-INSERT INTO TIMESTAMP_TBL VALUES ('97.041 17:32:01 UTC');
+reset datestyle;
+INSERT INTO TIMESTAMP_TBL VALUES ('1997.041 17:32:01 UTC');
 -- Check date conversion and date arithmetic
 INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
 INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
index a383ac2f6167290f00fcb95032f6691fd963641e..49525518c7be580c29a29b5cf7df300e4655275b 100644 (file)
@@ -92,9 +92,11 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997-02-10 17:32:01 PST');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('02-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('19970210 173201 PST');
+set datestyle to ymd;
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('97FEB10 5:32:01PM UTC');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('97/02/10 17:32:01 UTC');
-INSERT INTO TIMESTAMPTZ_TBL VALUES ('97.041 17:32:01 UTC');
+reset datestyle;
+INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997.041 17:32:01 UTC');
 -- Check date conversion and date arithmetic
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997-06-10 18:32:01 PDT');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 10 17:32:01 1997');
index 037d6f83ec4df0ff1bf82a939829bb6b2bed21d7..230d2befe1febea4f354eb4477bc684e0190545c 100644 (file)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.31 2003/05/14 03:26:03 tgl Exp $
+# $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.32 2003/07/29 00:03:19 tgl Exp $
 
 me=`basename $0`
 : ${TMPDIR=/tmp}
@@ -191,7 +191,7 @@ esac
 # ----------
 
 PGTZ='PST8PDT'; export PGTZ
-PGDATESTYLE='ISO,US'; export PGDATESTYLE
+PGDATESTYLE='ISO, MDY'; export PGDATESTYLE
 
 
 # ----------
@@ -432,7 +432,7 @@ PSQL="$bindir/psql -q -X $psql_options"
 # ----------
 
 PGTZ='PST8PDT'; export PGTZ
-PGDATESTYLE='Postgres,US'; export PGDATESTYLE
+PGDATESTYLE='Postgres, MDY'; export PGDATESTYLE
 
 
 # ----------
index 88ac83b5add389dd8caec91fa823c9697b8d4b30..c9171b28bdd0f47b5789c00a2c19f6536c8d4fac 100644 (file)
@@ -3,7 +3,7 @@
 --
 -- needed so tests pass even in Australia
 SET australian_timezones = 'off';
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 
 --
 -- Test various input formats
@@ -20,7 +20,11 @@ SELECT timestamp with time zone '2001-12-27 04:05:06.789-08';
 SELECT timestamp with time zone '2001.12.27 04:05:06.789-08';
 SELECT timestamp with time zone '2001/12/27 04:05:06.789-08';
 SELECT timestamp with time zone '12/27/2001 04:05:06.789-08';
+-- should fail in mdy mode:
 SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
+set datestyle to dmy;
+SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
+reset datestyle;
 SELECT timestamp with time zone 'Y2001M12D27H04M05S06.789+08';
 SELECT timestamp with time zone 'Y2001M12D27H04M05S06.789-08';
 SELECT timestamp with time zone 'Y2001M12D27H04MM05S06.789+08';
@@ -36,8 +40,8 @@ SELECT timestamp with time zone 'J2452271T040506-08';
 SELECT timestamp with time zone 'J2452271T040506.789+08';
 SELECT timestamp with time zone 'J2452271T040506.789-08';
 -- German/European-style dates with periods as delimiters
-SELECT timestamp with time zone '27.12.2001 04:05:06.789+08';
-SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789+08';
+SELECT timestamp with time zone '12.27.2001 04:05:06.789-08';
 SET DateStyle = 'German';
 SELECT timestamp with time zone '27.12.2001 04:05:06.789+08';
 SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
@@ -53,7 +57,7 @@ SELECT time with time zone 'T040506.789+08';
 SELECT time with time zone 'T040506.789-08';
 SELECT time with time zone 'T040506.789 +08';
 SELECT time with time zone 'T040506.789 -08';
-SET DateStyle = 'Postgres,US';
+SET DateStyle = 'Postgres, MDY';
 
 --
 -- date, time arithmetic
index b08e81e80e472e141cc71538f4f4a0a48dda1234..48a9151a703a8e22ef166b57906dbfa3500ec104 100644 (file)
@@ -80,9 +80,11 @@ INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 PST');
 INSERT INTO TIMESTAMP_TBL VALUES ('Feb-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMP_TBL VALUES ('02-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 PST');
+set datestyle to ymd;
 INSERT INTO TIMESTAMP_TBL VALUES ('97FEB10 5:32:01PM UTC');
 INSERT INTO TIMESTAMP_TBL VALUES ('97/02/10 17:32:01 UTC');
-INSERT INTO TIMESTAMP_TBL VALUES ('97.041 17:32:01 UTC');
+reset datestyle;
+INSERT INTO TIMESTAMP_TBL VALUES ('1997.041 17:32:01 UTC');
 
 -- Check date conversion and date arithmetic
 INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
index e60bacb96246715b712f2eb9bd9c6f2ade4b84f3..71414f198e16047dcaa5444c800efb7bd7c212be 100644 (file)
@@ -74,9 +74,11 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997-02-10 17:32:01 PST');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('02-10-1997 17:32:01 PST');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('19970210 173201 PST');
+set datestyle to ymd;
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('97FEB10 5:32:01PM UTC');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('97/02/10 17:32:01 UTC');
-INSERT INTO TIMESTAMPTZ_TBL VALUES ('97.041 17:32:01 UTC');
+reset datestyle;
+INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997.041 17:32:01 UTC');
 
 -- Check date conversion and date arithmetic
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997-06-10 18:32:01 PDT');