Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bd96dd1

Browse files
committed
Allow a time zone to be specified (and silently ignored) in the input
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.
1 parent 37b247a commit bd96dd1

File tree

8 files changed

+86
-55
lines changed

8 files changed

+86
-55
lines changed

doc/src/sgml/datatype.sgml

+13-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.112 2003/01/29 01:08:42 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.113 2003/01/31 01:08:07 tgl Exp $
33
-->
44

55
<chapter id="datatype">
@@ -1488,14 +1488,21 @@ SELECT b, char_length(b) FROM test2;
14881488
</indexterm>
14891489

14901490
<para>
1491-
The <type>time</type> type can be specified as <type>time</type> or
1492-
as <type>time without time zone</type>. The optional precision
1493-
<replaceable>p</replaceable> should be between 0 and 6, and
1494-
defaults to the precision of the input time literal.
1491+
The time-of-day types are <type>time [
1492+
(<replaceable>p</replaceable>) ] without time zone</type> and
1493+
<type>time [ (<replaceable>p</replaceable>) ] with time
1494+
zone</type>. Writing just <type>time</type> is equivalent to
1495+
<type>time without time zone</type>.
14951496
</para>
14961497

14971498
<para>
1498-
<xref linkend="datatype-datetime-time-table"> shows the valid <type>time</type> inputs.
1499+
Valid input for these types consists of a time of day followed by an
1500+
optional time zone. (See <xref linkend="datatype-datetime-time-table">.)
1501+
The optional precision
1502+
<replaceable>p</replaceable> should be between 0 and 6, and
1503+
defaults to the precision of the input time literal. If a time zone
1504+
is specified in the input for <type>time without time zone</type>,
1505+
it is silently ignored.
14991506
</para>
15001507

15011508
<table id="datatype-datetime-time-table">
@@ -1536,27 +1543,6 @@ SELECT b, char_length(b) FROM test2;
15361543
<entry><literal>allballs</literal></entry>
15371544
<entry>same as 00:00:00</entry>
15381545
</row>
1539-
</tbody>
1540-
</tgroup>
1541-
</table>
1542-
1543-
<para>
1544-
The type <type>time with time zone</type> accepts all input also
1545-
legal for the <type>time</type> type, appended with a legal time
1546-
zone, as shown in <xref
1547-
linkend="datatype-datetime-timetz-table">.
1548-
</para>
1549-
1550-
<table id="datatype-datetime-timetz-table">
1551-
<title>Time With Time Zone Input</title>
1552-
<tgroup cols="2">
1553-
<thead>
1554-
<row>
1555-
<entry>Example</entry>
1556-
<entry>Description</entry>
1557-
</row>
1558-
</thead>
1559-
<tbody>
15601546
<row>
15611547
<entry>04:05:06.789-8</entry>
15621548
<entry>ISO 8601</entry>

src/backend/utils/adt/date.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.77 2003/01/29 01:08:42 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.78 2003/01/31 01:08:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -511,6 +511,7 @@ time_in(PG_FUNCTION_ARGS)
511511
fsec_t fsec;
512512
struct tm tt,
513513
*tm = &tt;
514+
int tz;
514515
int nf;
515516
char lowstr[MAXDATELEN + 1];
516517
char *field[MAXDATEFIELDS];
@@ -521,7 +522,7 @@ time_in(PG_FUNCTION_ARGS)
521522
elog(ERROR, "Bad time external representation (too long) '%s'", str);
522523

523524
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
524-
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, NULL) != 0))
525+
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
525526
elog(ERROR, "Bad time external representation '%s'", str);
526527

527528
tm2time(tm, fsec, &result);

src/test/regress/expected/horology-no-DST-before-1970.out

+21-5
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,31 @@ SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
196196
(1 row)
197197

198198
SET DateStyle = 'ISO';
199-
-- Reject time without time zone having a time zone specified
199+
-- As of 7.4, allow time without time zone having a time zone specified
200200
SELECT time without time zone '040506.789+08';
201-
ERROR: Bad time external representation '040506.789+08'
201+
time
202+
---------------
203+
04:05:06.7890
204+
(1 row)
205+
202206
SELECT time without time zone '040506.789-08';
203-
ERROR: Bad time external representation '040506.789-08'
207+
time
208+
---------------
209+
04:05:06.7890
210+
(1 row)
211+
204212
SELECT time without time zone 'T040506.789+08';
205-
ERROR: Bad time external representation 'T040506.789+08'
213+
time
214+
---------------
215+
04:05:06.7890
216+
(1 row)
217+
206218
SELECT time without time zone 'T040506.789-08';
207-
ERROR: Bad time external representation 'T040506.789-08'
219+
time
220+
---------------
221+
04:05:06.7890
222+
(1 row)
223+
208224
SELECT time with time zone '040506.789+08';
209225
timetz
210226
------------------

src/test/regress/expected/horology-solaris-1947.out

+21-5
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,31 @@ SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
196196
(1 row)
197197

198198
SET DateStyle = 'ISO';
199-
-- Reject time without time zone having a time zone specified
199+
-- As of 7.4, allow time without time zone having a time zone specified
200200
SELECT time without time zone '040506.789+08';
201-
ERROR: Bad time external representation '040506.789+08'
201+
time
202+
---------------
203+
04:05:06.7890
204+
(1 row)
205+
202206
SELECT time without time zone '040506.789-08';
203-
ERROR: Bad time external representation '040506.789-08'
207+
time
208+
---------------
209+
04:05:06.7890
210+
(1 row)
211+
204212
SELECT time without time zone 'T040506.789+08';
205-
ERROR: Bad time external representation 'T040506.789+08'
213+
time
214+
---------------
215+
04:05:06.7890
216+
(1 row)
217+
206218
SELECT time without time zone 'T040506.789-08';
207-
ERROR: Bad time external representation 'T040506.789-08'
219+
time
220+
---------------
221+
04:05:06.7890
222+
(1 row)
223+
208224
SELECT time with time zone '040506.789+08';
209225
timetz
210226
------------------

src/test/regress/expected/horology.out

+21-5
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,31 @@ SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
196196
(1 row)
197197

198198
SET DateStyle = 'ISO';
199-
-- Reject time without time zone having a time zone specified
199+
-- As of 7.4, allow time without time zone having a time zone specified
200200
SELECT time without time zone '040506.789+08';
201-
ERROR: Bad time external representation '040506.789+08'
201+
time
202+
---------------
203+
04:05:06.7890
204+
(1 row)
205+
202206
SELECT time without time zone '040506.789-08';
203-
ERROR: Bad time external representation '040506.789-08'
207+
time
208+
---------------
209+
04:05:06.7890
210+
(1 row)
211+
204212
SELECT time without time zone 'T040506.789+08';
205-
ERROR: Bad time external representation 'T040506.789+08'
213+
time
214+
---------------
215+
04:05:06.7890
216+
(1 row)
217+
206218
SELECT time without time zone 'T040506.789-08';
207-
ERROR: Bad time external representation 'T040506.789-08'
219+
time
220+
---------------
221+
04:05:06.7890
222+
(1 row)
223+
208224
SELECT time with time zone '040506.789+08';
209225
timetz
210226
------------------

src/test/regress/expected/time.out

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
CREATE TABLE TIME_TBL (f1 time(2));
55
INSERT INTO TIME_TBL VALUES ('00:00');
66
INSERT INTO TIME_TBL VALUES ('01:00');
7-
INSERT INTO TIME_TBL VALUES ('02:03');
8-
INSERT INTO TIME_TBL VALUES ('07:07 PST');
9-
ERROR: Bad time external representation '07:07 PST'
10-
INSERT INTO TIME_TBL VALUES ('08:08 EDT');
11-
ERROR: Bad time external representation '08:08 EDT'
12-
INSERT INTO TIME_TBL VALUES ('11:59');
7+
-- as of 7.4, timezone spec should be accepted and ignored
8+
INSERT INTO TIME_TBL VALUES ('02:03 PST');
9+
INSERT INTO TIME_TBL VALUES ('11:59 EDT');
1310
INSERT INTO TIME_TBL VALUES ('12:00');
1411
INSERT INTO TIME_TBL VALUES ('12:01');
1512
INSERT INTO TIME_TBL VALUES ('23:59');

src/test/regress/sql/horology.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SET DateStyle = 'German';
4242
SELECT timestamp with time zone '27.12.2001 04:05:06.789+08';
4343
SELECT timestamp with time zone '27.12.2001 04:05:06.789-08';
4444
SET DateStyle = 'ISO';
45-
-- Reject time without time zone having a time zone specified
45+
-- As of 7.4, allow time without time zone having a time zone specified
4646
SELECT time without time zone '040506.789+08';
4747
SELECT time without time zone '040506.789-08';
4848
SELECT time without time zone 'T040506.789+08';

src/test/regress/sql/time.sql

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ CREATE TABLE TIME_TBL (f1 time(2));
66

77
INSERT INTO TIME_TBL VALUES ('00:00');
88
INSERT INTO TIME_TBL VALUES ('01:00');
9-
INSERT INTO TIME_TBL VALUES ('02:03');
10-
INSERT INTO TIME_TBL VALUES ('07:07 PST');
11-
INSERT INTO TIME_TBL VALUES ('08:08 EDT');
12-
INSERT INTO TIME_TBL VALUES ('11:59');
9+
-- as of 7.4, timezone spec should be accepted and ignored
10+
INSERT INTO TIME_TBL VALUES ('02:03 PST');
11+
INSERT INTO TIME_TBL VALUES ('11:59 EDT');
1312
INSERT INTO TIME_TBL VALUES ('12:00');
1413
INSERT INTO TIME_TBL VALUES ('12:01');
1514
INSERT INTO TIME_TBL VALUES ('23:59');

0 commit comments

Comments
 (0)