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

Commit 208d3a7

Browse files
committed
Correct/improve the datetime_precision field in the information schema.
In particular, always show 0 for the date type instead of null, and show 6 (the default) for time, timestamp, and interval without a declared precision. This is now in fuller conformance with the SQL standard. Also clarify the documentation about this. discovered and analyzed by Konstantin Izmailov and Tom Lane
1 parent 5cca35a commit 208d3a7

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

doc/src/sgml/information_schema.sgml

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.38 2009/02/06 21:15:11 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.39 2009/06/10 07:03:34 petere Exp $ -->
22

33
<chapter id="information-schema">
44
<title>The Information Schema</title>
@@ -395,9 +395,12 @@
395395
<entry><literal>datetime_precision</literal></entry>
396396
<entry><type>cardinal_number</type></entry>
397397
<entry>
398-
If <literal>data_type</literal> identifies a date, time, or
399-
interval type, the declared precision; null for all other data
400-
types or if no precision was declared.
398+
If <literal>data_type</literal> identifies a date, time,
399+
timestamp, or interval type, this column contains the (declared
400+
or implicit) fractional seconds precision of the type for this
401+
attribute, that is, the number of decimal digits maintained
402+
following the decimal point in the seconds value. For all
403+
other data types, this column is null.
401404
</entry>
402405
</row>
403406

@@ -995,9 +998,12 @@
995998
<entry><literal>datetime_precision</literal></entry>
996999
<entry><type>cardinal_number</type></entry>
9971000
<entry>
998-
If <literal>data_type</literal> identifies a date, time, or
999-
interval type, the declared precision; null for all other data
1000-
types or if no precision was declared.
1001+
If <literal>data_type</literal> identifies a date, time,
1002+
timestamp, or interval type, this column contains the (declared
1003+
or implicit) fractional seconds precision of the type for this
1004+
column, that is, the number of decimal digits maintained
1005+
following the decimal point in the seconds value. For all
1006+
other data types, this column is null.
10011007
</entry>
10021008
</row>
10031009

@@ -1729,7 +1735,7 @@
17291735
<entry><type>cardinal_number</type></entry>
17301736
<entry>
17311737
If the domain has a numeric type, this column contains the
1732-
(declared or implicit) precision of the type for this column.
1738+
(declared or implicit) precision of the type for this domain.
17331739
The precision indicates the number of significant digits. It
17341740
can be expressed in decimal (base 10) or binary (base 2) terms,
17351741
as specified in the column
@@ -1755,7 +1761,7 @@
17551761
<entry><type>cardinal_number</type></entry>
17561762
<entry>
17571763
If the domain has an exact numeric type, this column contains
1758-
the (declared or implicit) scale of the type for this column.
1764+
the (declared or implicit) scale of the type for this domain.
17591765
The scale indicates the number of significant digits to the
17601766
right of the decimal point. It can be expressed in decimal
17611767
(base 10) or binary (base 2) terms, as specified in the column
@@ -1768,9 +1774,12 @@
17681774
<entry><literal>datetime_precision</literal></entry>
17691775
<entry><type>cardinal_number</type></entry>
17701776
<entry>
1771-
If the domain has a date, time, or interval type, the declared
1772-
precision; null for all other data types or if no precision was
1773-
declared.
1777+
If <literal>data_type</literal> identifies a date, time,
1778+
timestamp, or interval type, this column contains the (declared
1779+
or implicit) fractional seconds precision of the type for this
1780+
domain, that is, the number of decimal digits maintained
1781+
following the decimal point in the seconds value. For all
1782+
other data types, this column is null.
17741783
</entry>
17751784
</row>
17761785

src/backend/catalog/information_schema.sql

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2003-2009, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.53 2009/02/24 10:06:32 petere Exp $
7+
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.54 2009/06/10 07:03:34 petere Exp $
88
*/
99

1010
/*
@@ -160,12 +160,12 @@ CREATE FUNCTION _pg_datetime_precision(typid oid, typmod int4) RETURNS integer
160160
RETURNS NULL ON NULL INPUT
161161
AS
162162
$$SELECT
163-
CASE WHEN $2 = -1 /* default typmod */
164-
THEN null
163+
CASE WHEN $1 IN (1082) /* date */
164+
THEN 0
165165
WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */
166-
THEN $2
166+
THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 END
167167
WHEN $1 IN (1186) /* interval */
168-
THEN $2 & 65535
168+
THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 & 65535 END
169169
ELSE null
170170
END$$;
171171

0 commit comments

Comments
 (0)