Commit 0527a454 authored by Peter Eisentraut's avatar Peter Eisentraut

Implement information schema interval_type columns

Also correct reporting of interval precision when field restrictions
are specified in the typmod.
parent 80a1d169
...@@ -483,7 +483,15 @@ ...@@ -483,7 +483,15 @@
<row> <row>
<entry><literal>interval_type</literal></entry> <entry><literal>interval_type</literal></entry>
<entry><type>character_data</type></entry> <entry><type>character_data</type></entry>
<entry>Not yet implemented</entry> <entry>
If <literal>data_type</literal> identifies an interval type,
this column contains the specification which fields the
intervals include for this attribute, e.g., <literal>YEAR TO
MONTH</literal>, <literal>DAY TO SECOND</literal>, etc. If no
field restrictions were specified (that is, the interval
accepts all fields), and for all other data types, this field
is null.
</entry>
</row> </row>
<row> <row>
...@@ -1343,7 +1351,15 @@ ...@@ -1343,7 +1351,15 @@
<row> <row>
<entry><literal>interval_type</literal></entry> <entry><literal>interval_type</literal></entry>
<entry><type>character_data</type></entry> <entry><type>character_data</type></entry>
<entry>Not yet implemented</entry> <entry>
If <literal>data_type</literal> identifies an interval type,
this column contains the specification which fields the
intervals include for this column, e.g., <literal>YEAR TO
MONTH</literal>, <literal>DAY TO SECOND</literal>, etc. If no
field restrictions were specified (that is, the interval
accepts all fields), and for all other data types, this field
is null.
</entry>
</row> </row>
<row> <row>
...@@ -2144,7 +2160,15 @@ ...@@ -2144,7 +2160,15 @@
<row> <row>
<entry><literal>interval_type</literal></entry> <entry><literal>interval_type</literal></entry>
<entry><type>character_data</type></entry> <entry><type>character_data</type></entry>
<entry>Not yet implemented</entry> <entry>
If <literal>data_type</literal> identifies an interval type,
this column contains the specification which fields the
intervals include for this domain, e.g., <literal>YEAR TO
MONTH</literal>, <literal>DAY TO SECOND</literal>, etc. If no
field restrictions were specified (that is, the interval
accepts all fields), and for all other data types, this field
is null.
</entry>
</row> </row>
<row> <row>
......
...@@ -158,7 +158,18 @@ $$SELECT ...@@ -158,7 +158,18 @@ $$SELECT
WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */ WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */
THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 END THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 END
WHEN $1 IN (1186) /* interval */ WHEN $1 IN (1186) /* interval */
THEN CASE WHEN $2 < 0 THEN 6 ELSE $2 & 65535 END THEN CASE WHEN $2 < 0 OR $2 & 65535 = 65535 THEN 6 ELSE $2 & 65535 END
ELSE null
END$$;
CREATE FUNCTION _pg_interval_type(typid oid, mod int4) RETURNS text
LANGUAGE sql
IMMUTABLE
RETURNS NULL ON NULL INPUT
AS
$$SELECT
CASE WHEN $1 IN (1186) /* interval */
THEN upper(substring(format_type($1, $2) from 'interval[()0-9]* #"%#"' for '#'))
ELSE null ELSE null
END$$; END$$;
...@@ -321,7 +332,10 @@ CREATE VIEW attributes AS ...@@ -321,7 +332,10 @@ CREATE VIEW attributes AS
AS cardinal_number) AS cardinal_number)
AS datetime_precision, AS datetime_precision,
CAST(null AS character_data) AS interval_type, -- FIXME CAST(
_pg_interval_type(_pg_truetypid(a, t), _pg_truetypmod(a, t))
AS character_data)
AS interval_type,
CAST(null AS cardinal_number) AS interval_precision, CAST(null AS cardinal_number) AS interval_precision,
CAST(current_database() AS sql_identifier) AS attribute_udt_catalog, CAST(current_database() AS sql_identifier) AS attribute_udt_catalog,
...@@ -670,7 +684,10 @@ CREATE VIEW columns AS ...@@ -670,7 +684,10 @@ CREATE VIEW columns AS
AS cardinal_number) AS cardinal_number)
AS datetime_precision, AS datetime_precision,
CAST(null AS character_data) AS interval_type, -- FIXME CAST(
_pg_interval_type(_pg_truetypid(a, t), _pg_truetypmod(a, t))
AS character_data)
AS interval_type,
CAST(null AS cardinal_number) AS interval_precision, CAST(null AS cardinal_number) AS interval_precision,
CAST(null AS sql_identifier) AS character_set_catalog, CAST(null AS sql_identifier) AS character_set_catalog,
...@@ -936,7 +953,10 @@ CREATE VIEW domains AS ...@@ -936,7 +953,10 @@ CREATE VIEW domains AS
AS cardinal_number) AS cardinal_number)
AS datetime_precision, AS datetime_precision,
CAST(null AS character_data) AS interval_type, -- FIXME CAST(
_pg_interval_type(t.typbasetype, t.typtypmod)
AS character_data)
AS interval_type,
CAST(null AS cardinal_number) AS interval_precision, CAST(null AS cardinal_number) AS interval_precision,
CAST(t.typdefault AS character_data) AS domain_default, CAST(t.typdefault AS character_data) AS domain_default,
......
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