Commit 208d3a75 authored by Peter Eisentraut's avatar Peter Eisentraut

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
parent 5cca35a6
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.38 2009/02/06 21:15:11 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.39 2009/06/10 07:03:34 petere Exp $ -->
<chapter id="information-schema"> <chapter id="information-schema">
<title>The Information Schema</title> <title>The Information Schema</title>
...@@ -395,9 +395,12 @@ ...@@ -395,9 +395,12 @@
<entry><literal>datetime_precision</literal></entry> <entry><literal>datetime_precision</literal></entry>
<entry><type>cardinal_number</type></entry> <entry><type>cardinal_number</type></entry>
<entry> <entry>
If <literal>data_type</literal> identifies a date, time, or If <literal>data_type</literal> identifies a date, time,
interval type, the declared precision; null for all other data timestamp, or interval type, this column contains the (declared
types or if no precision was declared. or implicit) fractional seconds precision of the type for this
attribute, that is, the number of decimal digits maintained
following the decimal point in the seconds value. For all
other data types, this column is null.
</entry> </entry>
</row> </row>
...@@ -995,9 +998,12 @@ ...@@ -995,9 +998,12 @@
<entry><literal>datetime_precision</literal></entry> <entry><literal>datetime_precision</literal></entry>
<entry><type>cardinal_number</type></entry> <entry><type>cardinal_number</type></entry>
<entry> <entry>
If <literal>data_type</literal> identifies a date, time, or If <literal>data_type</literal> identifies a date, time,
interval type, the declared precision; null for all other data timestamp, or interval type, this column contains the (declared
types or if no precision was declared. or implicit) fractional seconds precision of the type for this
column, that is, the number of decimal digits maintained
following the decimal point in the seconds value. For all
other data types, this column is null.
</entry> </entry>
</row> </row>
...@@ -1729,7 +1735,7 @@ ...@@ -1729,7 +1735,7 @@
<entry><type>cardinal_number</type></entry> <entry><type>cardinal_number</type></entry>
<entry> <entry>
If the domain has a numeric type, this column contains the If the domain has a numeric type, this column contains the
(declared or implicit) precision of the type for this column. (declared or implicit) precision of the type for this domain.
The precision indicates the number of significant digits. It The precision indicates the number of significant digits. It
can be expressed in decimal (base 10) or binary (base 2) terms, can be expressed in decimal (base 10) or binary (base 2) terms,
as specified in the column as specified in the column
...@@ -1755,7 +1761,7 @@ ...@@ -1755,7 +1761,7 @@
<entry><type>cardinal_number</type></entry> <entry><type>cardinal_number</type></entry>
<entry> <entry>
If the domain has an exact numeric type, this column contains If the domain has an exact numeric type, this column contains
the (declared or implicit) scale of the type for this column. the (declared or implicit) scale of the type for this domain.
The scale indicates the number of significant digits to the The scale indicates the number of significant digits to the
right of the decimal point. It can be expressed in decimal right of the decimal point. It can be expressed in decimal
(base 10) or binary (base 2) terms, as specified in the column (base 10) or binary (base 2) terms, as specified in the column
...@@ -1768,9 +1774,12 @@ ...@@ -1768,9 +1774,12 @@
<entry><literal>datetime_precision</literal></entry> <entry><literal>datetime_precision</literal></entry>
<entry><type>cardinal_number</type></entry> <entry><type>cardinal_number</type></entry>
<entry> <entry>
If the domain has a date, time, or interval type, the declared If <literal>data_type</literal> identifies a date, time,
precision; null for all other data types or if no precision was timestamp, or interval type, this column contains the (declared
declared. or implicit) fractional seconds precision of the type for this
domain, that is, the number of decimal digits maintained
following the decimal point in the seconds value. For all
other data types, this column is null.
</entry> </entry>
</row> </row>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Copyright (c) 2003-2009, PostgreSQL Global Development Group * Copyright (c) 2003-2009, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.53 2009/02/24 10:06:32 petere Exp $ * $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.54 2009/06/10 07:03:34 petere Exp $
*/ */
/* /*
...@@ -160,12 +160,12 @@ CREATE FUNCTION _pg_datetime_precision(typid oid, typmod int4) RETURNS integer ...@@ -160,12 +160,12 @@ CREATE FUNCTION _pg_datetime_precision(typid oid, typmod int4) RETURNS integer
RETURNS NULL ON NULL INPUT RETURNS NULL ON NULL INPUT
AS AS
$$SELECT $$SELECT
CASE WHEN $2 = -1 /* default typmod */ CASE WHEN $1 IN (1082) /* date */
THEN null THEN 0
WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */ WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */
THEN $2 THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 END
WHEN $1 IN (1186) /* interval */ WHEN $1 IN (1186) /* interval */
THEN $2 & 65535 THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 & 65535 END
ELSE null ELSE null
END$$; END$$;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment