Skip to content

Commit 0527a45

Browse files
committed
Implement information schema interval_type columns
Also correct reporting of interval precision when field restrictions are specified in the typmod.
1 parent 80a1d16 commit 0527a45

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

doc/src/sgml/information_schema.sgml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,15 @@
483483
<row>
484484
<entry><literal>interval_type</literal></entry>
485485
<entry><type>character_data</type></entry>
486-
<entry>Not yet implemented</entry>
486+
<entry>
487+
If <literal>data_type</literal> identifies an interval type,
488+
this column contains the specification which fields the
489+
intervals include for this attribute, e.g., <literal>YEAR TO
490+
MONTH</literal>, <literal>DAY TO SECOND</literal>, etc. If no
491+
field restrictions were specified (that is, the interval
492+
accepts all fields), and for all other data types, this field
493+
is null.
494+
</entry>
487495
</row>
488496

489497
<row>
@@ -1343,7 +1351,15 @@
13431351
<row>
13441352
<entry><literal>interval_type</literal></entry>
13451353
<entry><type>character_data</type></entry>
1346-
<entry>Not yet implemented</entry>
1354+
<entry>
1355+
If <literal>data_type</literal> identifies an interval type,
1356+
this column contains the specification which fields the
1357+
intervals include for this column, e.g., <literal>YEAR TO
1358+
MONTH</literal>, <literal>DAY TO SECOND</literal>, etc. If no
1359+
field restrictions were specified (that is, the interval
1360+
accepts all fields), and for all other data types, this field
1361+
is null.
1362+
</entry>
13471363
</row>
13481364

13491365
<row>
@@ -2144,7 +2160,15 @@
21442160
<row>
21452161
<entry><literal>interval_type</literal></entry>
21462162
<entry><type>character_data</type></entry>
2147-
<entry>Not yet implemented</entry>
2163+
<entry>
2164+
If <literal>data_type</literal> identifies an interval type,
2165+
this column contains the specification which fields the
2166+
intervals include for this domain, e.g., <literal>YEAR TO
2167+
MONTH</literal>, <literal>DAY TO SECOND</literal>, etc. If no
2168+
field restrictions were specified (that is, the interval
2169+
accepts all fields), and for all other data types, this field
2170+
is null.
2171+
</entry>
21482172
</row>
21492173

21502174
<row>

src/backend/catalog/information_schema.sql

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,18 @@ $$SELECT
158158
WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */
159159
THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 END
160160
WHEN $1 IN (1186) /* interval */
161-
THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 & 65535 END
161+
THEN CASE WHEN $2 < 0 OR $2 & 65535 = 65535 THEN 6 ELSE $2 & 65535 END
162+
ELSE null
163+
END$$;
164+
165+
CREATE FUNCTION _pg_interval_type(typid oid, mod int4) RETURNS text
166+
LANGUAGE sql
167+
IMMUTABLE
168+
RETURNS NULL ON NULL INPUT
169+
AS
170+
$$SELECT
171+
CASE WHEN $1 IN (1186) /* interval */
172+
THEN upper(substring(format_type($1, $2) from 'interval[()0-9]* #"%#"' for '#'))
162173
ELSE null
163174
END$$;
164175

@@ -321,7 +332,10 @@ CREATE VIEW attributes AS
321332
AS cardinal_number)
322333
AS datetime_precision,
323334

324-
CAST(null AS character_data) AS interval_type, -- FIXME
335+
CAST(
336+
_pg_interval_type(_pg_truetypid(a, t), _pg_truetypmod(a, t))
337+
AS character_data)
338+
AS interval_type,
325339
CAST(null AS cardinal_number) AS interval_precision,
326340

327341
CAST(current_database() AS sql_identifier) AS attribute_udt_catalog,
@@ -670,7 +684,10 @@ CREATE VIEW columns AS
670684
AS cardinal_number)
671685
AS datetime_precision,
672686

673-
CAST(null AS character_data) AS interval_type, -- FIXME
687+
CAST(
688+
_pg_interval_type(_pg_truetypid(a, t), _pg_truetypmod(a, t))
689+
AS character_data)
690+
AS interval_type,
674691
CAST(null AS cardinal_number) AS interval_precision,
675692

676693
CAST(null AS sql_identifier) AS character_set_catalog,
@@ -936,7 +953,10 @@ CREATE VIEW domains AS
936953
AS cardinal_number)
937954
AS datetime_precision,
938955

939-
CAST(null AS character_data) AS interval_type, -- FIXME
956+
CAST(
957+
_pg_interval_type(t.typbasetype, t.typtypmod)
958+
AS character_data)
959+
AS interval_type,
940960
CAST(null AS cardinal_number) AS interval_precision,
941961

942962
CAST(t.typdefault AS character_data) AS domain_default,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy