]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Allow a time zone to be specified (and silently ignored) in the input
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 31 Jan 2003 01:08:08 +0000 (01:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 31 Jan 2003 01:08:08 +0000 (01:08 +0000)
for type 'time without time zone', as we already did for type
'timestamp without time zone'.  This patch was proposed by Tom Lockhart
on 7-Nov-02, but he never got around to applying it.  Adjust regression
tests and documentation to match.

doc/src/sgml/datatype.sgml
src/backend/utils/adt/date.c
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/time.out
src/test/regress/sql/horology.sql
src/test/regress/sql/time.sql

index 9bbd5146c2a6c51589729e4b4343330a1efddc4b..4f166e06bc73173232cc3a86f785996d938ab60b 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.112 2003/01/29 01:08:42 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.113 2003/01/31 01:08:07 tgl Exp $
 -->
 
  <chapter id="datatype">
@@ -1488,14 +1488,21 @@ SELECT b, char_length(b) FROM test2;
      </indexterm>
 
      <para>
-      The <type>time</type> type can be specified as <type>time</type> or
-      as <type>time without time zone</type>. The optional precision
-      <replaceable>p</replaceable> should be between 0 and 6, and
-      defaults to the precision of the input time literal.
+      The time-of-day types are <type>time [
+      (<replaceable>p</replaceable>) ] without time zone</type> and
+      <type>time [ (<replaceable>p</replaceable>) ] with time
+      zone</type>.  Writing just <type>time</type> is equivalent to
+      <type>time without time zone</type>.
      </para>
 
      <para>
-      <xref linkend="datatype-datetime-time-table"> shows the valid <type>time</type> inputs.
+      Valid input for these types consists of a time of day followed by an
+      optional time zone. (See <xref linkend="datatype-datetime-time-table">.)
+      The optional precision
+      <replaceable>p</replaceable> should be between 0 and 6, and
+      defaults to the precision of the input time literal.  If a time zone
+      is specified in the input for <type>time without time zone</type>,
+      it is silently ignored.
      </para>
 
       <table id="datatype-datetime-time-table">
@@ -1536,27 +1543,6 @@ SELECT b, char_length(b) FROM test2;
          <entry><literal>allballs</literal></entry>
          <entry>same as 00:00:00</entry>
         </row>
-       </tbody>
-       </tgroup>
-      </table>
-
-     <para>
-      The type <type>time with time zone</type> accepts all input also
-      legal for the <type>time</type> type, appended with a legal time
-      zone, as shown in <xref
-      linkend="datatype-datetime-timetz-table">.
-     </para>
-
-      <table id="datatype-datetime-timetz-table">
-       <title>Time With Time Zone Input</title>
-       <tgroup cols="2">
-       <thead>
-       <row>
-        <entry>Example</entry>
-        <entry>Description</entry>
-       </row>
-       </thead>
-       <tbody>
        <row>
         <entry>04:05:06.789-8</entry>
         <entry>ISO 8601</entry>
index 90f41ad817d557d2577588bc5ad6825ab69a4c3c..09d0e9aa25603062d5e210c3b4e06cb1147203e6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.77 2003/01/29 01:08:42 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.78 2003/01/31 01:08:08 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -511,6 +511,7 @@ time_in(PG_FUNCTION_ARGS)
        fsec_t          fsec;
        struct tm       tt,
                           *tm = &tt;
+       int                     tz;
        int                     nf;
        char            lowstr[MAXDATELEN + 1];
        char       *field[MAXDATEFIELDS];
@@ -521,7 +522,7 @@ time_in(PG_FUNCTION_ARGS)
                elog(ERROR, "Bad time external representation (too long) '%s'", str);
 
        if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
-        || (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, NULL) != 0))
+        || (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
                elog(ERROR, "Bad time external representation '%s'", str);
 
        tm2time(tm, fsec, &result);
index b8b7423ec520f01c286b2f5a72b5758255e2279f..ab40a6404ca182129bc576f50dffa244693aa6ee 100644 (file)
@@ -196,15 +196,31 @@ SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
 (1 row)
 
 SET DateStyle = 'ISO';
--- Reject time without time zone having a time zone specified
+-- As of 7.4, allow time without time zone having a time zone specified
 SELECT time without time zone '040506.789+08';
-ERROR:  Bad time external representation '040506.789+08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone '040506.789-08';
-ERROR:  Bad time external representation '040506.789-08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone 'T040506.789+08';
-ERROR:  Bad time external representation 'T040506.789+08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone 'T040506.789-08';
-ERROR:  Bad time external representation 'T040506.789-08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time with time zone '040506.789+08';
       timetz      
 ------------------
index 1601a346f01612f152b18e3568be3f10fcf7fd0e..222ee3036793d9d4de89f8ac549362de25c21088 100644 (file)
@@ -196,15 +196,31 @@ SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
 (1 row)
 
 SET DateStyle = 'ISO';
--- Reject time without time zone having a time zone specified
+-- As of 7.4, allow time without time zone having a time zone specified
 SELECT time without time zone '040506.789+08';
-ERROR:  Bad time external representation '040506.789+08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone '040506.789-08';
-ERROR:  Bad time external representation '040506.789-08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone 'T040506.789+08';
-ERROR:  Bad time external representation 'T040506.789+08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone 'T040506.789-08';
-ERROR:  Bad time external representation 'T040506.789-08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time with time zone '040506.789+08';
       timetz      
 ------------------
index 294b7854106ba88388d0c70a8f92e559e4406447..2735641e396b922fded794abc4a7a9ef240fe94a 100644 (file)
@@ -196,15 +196,31 @@ SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
 (1 row)
 
 SET DateStyle = 'ISO';
--- Reject time without time zone having a time zone specified
+-- As of 7.4, allow time without time zone having a time zone specified
 SELECT time without time zone '040506.789+08';
-ERROR:  Bad time external representation '040506.789+08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone '040506.789-08';
-ERROR:  Bad time external representation '040506.789-08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone 'T040506.789+08';
-ERROR:  Bad time external representation 'T040506.789+08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time without time zone 'T040506.789-08';
-ERROR:  Bad time external representation 'T040506.789-08'
+     time      
+---------------
+ 04:05:06.7890
+(1 row)
+
 SELECT time with time zone '040506.789+08';
       timetz      
 ------------------
index ddefeadc34d30456b0f69758e7ac10db9fee5718..e8b2b6de3371b8c4997bc0a41519cff0ce37c055 100644 (file)
@@ -4,12 +4,9 @@
 CREATE TABLE TIME_TBL (f1 time(2));
 INSERT INTO TIME_TBL VALUES ('00:00');
 INSERT INTO TIME_TBL VALUES ('01:00');
-INSERT INTO TIME_TBL VALUES ('02:03');
-INSERT INTO TIME_TBL VALUES ('07:07 PST');
-ERROR:  Bad time external representation '07:07 PST'
-INSERT INTO TIME_TBL VALUES ('08:08 EDT');
-ERROR:  Bad time external representation '08:08 EDT'
-INSERT INTO TIME_TBL VALUES ('11:59');
+-- as of 7.4, timezone spec should be accepted and ignored
+INSERT INTO TIME_TBL VALUES ('02:03 PST');
+INSERT INTO TIME_TBL VALUES ('11:59 EDT');
 INSERT INTO TIME_TBL VALUES ('12:00');
 INSERT INTO TIME_TBL VALUES ('12:01');
 INSERT INTO TIME_TBL VALUES ('23:59');
index 6d767d23760a57816e29d1bd4bbeb7a01082078a..0af769a8b2ca62ce65ed69f393ff39c6653131db 100644 (file)
@@ -42,7 +42,7 @@ 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';
 SET DateStyle = 'ISO';
--- Reject time without time zone having a time zone specified
+-- As of 7.4, allow time without time zone having a time zone specified
 SELECT time without time zone '040506.789+08';
 SELECT time without time zone '040506.789-08';
 SELECT time without time zone 'T040506.789+08';
index 8ab8caa6077ea8bf527de80409b08f553498a8b4..510cc148549a5071d3bcdfea71cd65f5c59adbd5 100644 (file)
@@ -6,10 +6,9 @@ CREATE TABLE TIME_TBL (f1 time(2));
 
 INSERT INTO TIME_TBL VALUES ('00:00');
 INSERT INTO TIME_TBL VALUES ('01:00');
-INSERT INTO TIME_TBL VALUES ('02:03');
-INSERT INTO TIME_TBL VALUES ('07:07 PST');
-INSERT INTO TIME_TBL VALUES ('08:08 EDT');
-INSERT INTO TIME_TBL VALUES ('11:59');
+-- as of 7.4, timezone spec should be accepted and ignored
+INSERT INTO TIME_TBL VALUES ('02:03 PST');
+INSERT INTO TIME_TBL VALUES ('11:59 EDT');
 INSERT INTO TIME_TBL VALUES ('12:00');
 INSERT INTO TIME_TBL VALUES ('12:01');
 INSERT INTO TIME_TBL VALUES ('23:59');