Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit208d3a7

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 show6 (the default) for time, timestamp, and interval without a declaredprecision. 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 parent5cca35a commit208d3a7

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

‎doc/src/sgml/information_schema.sgml

Lines changed: 21 additions & 12 deletions
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 thiscolumn.
1738+
(declared or implicit) precision of the type for thisdomain.
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 thiscolumn.
1764+
the (declared or implicit) scale of the type for thisdomain.
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

Lines changed: 5 additions & 5 deletions
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
RETURNSNULLONNULL INPUT
161161
AS
162162
$$SELECT
163-
CASE WHEN $2=-1/*default typmod*/
164-
THENnull
163+
CASE WHEN $1IN (1082)/*date*/
164+
THEN0
165165
WHEN $1IN (1083,1114,1184,1266)/* time, timestamp, same + tz*/
166-
THEN$2
166+
THENCASE WHEN $2<0 THEN6 ELSE $2 END
167167
WHEN $1IN (1186)/* interval*/
168-
THEN $2 &65535
168+
THENCASE WHEN$2<0 THEN6 ELSE $2&65535 END
169169
ELSEnull
170170
END$$;
171171

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp