Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 615c384

Browse files
committed
Implement the collation columns of various information schema views
Fill in the collation columns of the views attributes, columns, domains, and element_types. Also update collation information in sql_implementation_info.
1 parent 5594d14 commit 615c384

File tree

2 files changed

+132
-54
lines changed

2 files changed

+132
-54
lines changed

doc/src/sgml/information_schema.sgml

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,53 @@
379379
</entry>
380380
</row>
381381

382+
<row>
383+
<entry><literal>character_set_catalog</literal></entry>
384+
<entry><type>sql_identifier</type></entry>
385+
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
386+
</row>
387+
388+
<row>
389+
<entry><literal>character_set_schema</literal></entry>
390+
<entry><type>sql_identifier</type></entry>
391+
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
392+
</row>
393+
394+
<row>
395+
<entry><literal>character_set_name</literal></entry>
396+
<entry><type>sql_identifier</type></entry>
397+
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
398+
</row>
399+
400+
<row>
401+
<entry><literal>collation_catalog</literal></entry>
402+
<entry><type>sql_identifier</type></entry>
403+
<entry>
404+
Name of the database containing the collation of the attribute
405+
(always the current database), null if default or the data type
406+
of the attribute is not collatable
407+
</entry>
408+
</row>
409+
410+
<row>
411+
<entry><literal>collation_schema</literal></entry>
412+
<entry><type>sql_identifier</type></entry>
413+
<entry>
414+
Name of the schema containing the collation of the attribute,
415+
null if default or the data type of the attribute is not
416+
collatable
417+
</entry>
418+
</row>
419+
420+
<row>
421+
<entry><literal>collation_name</literal></entry>
422+
<entry><type>sql_identifier</type></entry>
423+
<entry>
424+
Name of the collation of the attribute, null if default or the
425+
data type of the attribute is not collatable
426+
</entry>
427+
</row>
428+
382429
<row>
383430
<entry><literal>numeric_precision</literal></entry>
384431
<entry><type>cardinal_number</type></entry>
@@ -1321,19 +1368,29 @@
13211368
<row>
13221369
<entry><literal>collation_catalog</literal></entry>
13231370
<entry><type>sql_identifier</type></entry>
1324-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
1371+
<entry>
1372+
Name of the database containing the collation of the column
1373+
(always the current database), null if default or the data type
1374+
of the column is not collatable
1375+
</entry>
13251376
</row>
13261377

13271378
<row>
13281379
<entry><literal>collation_schema</literal></entry>
13291380
<entry><type>sql_identifier</type></entry>
1330-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
1381+
<entry>
1382+
Name of the schema containing the collation of the column, null
1383+
if default or the data type of the column is not collatable
1384+
</entry>
13311385
</row>
13321386

13331387
<row>
13341388
<entry><literal>collation_name</literal></entry>
13351389
<entry><type>sql_identifier</type></entry>
1336-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
1390+
<entry>
1391+
Name of the collation of the column, null if default or the
1392+
data type of the column is not collatable
1393+
</entry>
13371394
</row>
13381395

13391396
<row>
@@ -1996,19 +2053,29 @@
19962053
<row>
19972054
<entry><literal>collation_catalog</literal></entry>
19982055
<entry><type>sql_identifier</type></entry>
1999-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
2056+
<entry>
2057+
Name of the database containing the collation of the domain
2058+
(always the current database), null if default or the data type
2059+
of the domain is not collatable
2060+
</entry>
20002061
</row>
20012062

20022063
<row>
20032064
<entry><literal>collation_schema</literal></entry>
20042065
<entry><type>sql_identifier</type></entry>
2005-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
2066+
<entry>
2067+
Name of the schema containing the collation of the domain, null
2068+
if default or the data type of the domain is not collatable
2069+
</entry>
20062070
</row>
20072071

20082072
<row>
20092073
<entry><literal>collation_name</literal></entry>
20102074
<entry><type>sql_identifier</type></entry>
2011-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
2075+
<entry>
2076+
Name of the collation of the column, null if default or the
2077+
data type of the domain is not collatable
2078+
</entry>
20122079
</row>
20132080

20142081
<row>
@@ -2275,19 +2342,30 @@ ORDER BY c.ordinal_position;
22752342
<row>
22762343
<entry><literal>collation_catalog</literal></entry>
22772344
<entry><type>sql_identifier</type></entry>
2278-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
2345+
<entry>
2346+
Name of the database containing the collation of the element
2347+
type (always the current database), null if default or the data
2348+
type of the element is not collatable
2349+
</entry>
22792350
</row>
22802351

22812352
<row>
22822353
<entry><literal>collation_schema</literal></entry>
22832354
<entry><type>sql_identifier</type></entry>
2284-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
2355+
<entry>
2356+
Name of the schema containing the collation of the element
2357+
type, null if default or the data type of the element is not
2358+
collatable
2359+
</entry>
22852360
</row>
22862361

22872362
<row>
22882363
<entry><literal>collation_name</literal></entry>
22892364
<entry><type>sql_identifier</type></entry>
2290-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
2365+
<entry>
2366+
Name of the collation of the element type, null if default or
2367+
the data type of the element is not collatable
2368+
</entry>
22912369
</row>
22922370

22932371
<row>
@@ -3025,19 +3103,19 @@ ORDER BY c.ordinal_position;
30253103
<row>
30263104
<entry><literal>collation_catalog</literal></entry>
30273105
<entry><type>sql_identifier</type></entry>
3028-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
3106+
<entry>Always null, since this information is not applied to parameter data types in <productname>PostgreSQL</></entry>
30293107
</row>
30303108

30313109
<row>
30323110
<entry><literal>collation_schema</literal></entry>
30333111
<entry><type>sql_identifier</type></entry>
3034-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
3112+
<entry>Always null, since this information is not applied to parameter data types in <productname>PostgreSQL</></entry>
30353113
</row>
30363114

30373115
<row>
30383116
<entry><literal>collation_name</literal></entry>
30393117
<entry><type>sql_identifier</type></entry>
3040-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
3118+
<entry>Always null, since this information is not applied to parameter data types in <productname>PostgreSQL</></entry>
30413119
</row>
30423120

30433121
<row>
@@ -3912,19 +3990,19 @@ ORDER BY c.ordinal_position;
39123990
<row>
39133991
<entry><literal>collation_catalog</literal></entry>
39143992
<entry><type>sql_identifier</type></entry>
3915-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
3993+
<entry>Always null, since this information is not applied to return data types in <productname>PostgreSQL</></entry>
39163994
</row>
39173995

39183996
<row>
39193997
<entry><literal>collation_schema</literal></entry>
39203998
<entry><type>sql_identifier</type></entry>
3921-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
3999+
<entry>Always null, since this information is not applied to return data types in <productname>PostgreSQL</></entry>
39224000
</row>
39234001

39244002
<row>
39254003
<entry><literal>collation_name</literal></entry>
39264004
<entry><type>sql_identifier</type></entry>
3927-
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
4005+
<entry>Always null, since this information is not applied to return data types in <productname>PostgreSQL</></entry>
39284006
</row>
39294007

39304008
<row>

src/backend/catalog/information_schema.sql

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ CREATE VIEW attributes AS
297297
CAST(null AS sql_identifier) AS character_set_schema,
298298
CAST(null AS sql_identifier) AS character_set_name,
299299

300-
CAST(null AS sql_identifier) AS collation_catalog,
301-
CAST(null AS sql_identifier) AS collation_schema,
302-
CAST(null AS sql_identifier) AS collation_name,
300+
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
301+
CAST(nco.nspname AS sql_identifier) AS collation_schema,
302+
CAST(co.collname AS sql_identifier) AS collation_name,
303303

304304
CAST(
305305
_pg_numeric_precision(_pg_truetypid(a, t), _pg_truetypmod(a, t))
@@ -336,14 +336,13 @@ CREATE VIEW attributes AS
336336
CAST(a.attnum AS sql_identifier) AS dtd_identifier,
337337
CAST('NO' AS yes_or_no) AS is_derived_reference_attribute
338338

339-
FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum),
340-
pg_class c, pg_namespace nc,
341-
(pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid))
339+
FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum)
340+
JOIN (pg_class c JOIN pg_namespace nc ON (c.relnamespace = nc.oid)) ON a.attrelid = c.oid
341+
JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON a.atttypid = t.oid
342+
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
343+
ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
342344

343-
WHERE a.attrelid = c.oid
344-
AND a.atttypid = t.oid
345-
AND nc.oid = c.relnamespace
346-
AND a.attnum > 0 AND NOT a.attisdropped
345+
WHERE a.attnum > 0 AND NOT a.attisdropped
347346
AND c.relkind in ('c');
348347

349348
GRANT SELECT ON attributes TO PUBLIC;
@@ -678,9 +677,9 @@ CREATE VIEW columns AS
678677
CAST(null AS sql_identifier) AS character_set_schema,
679678
CAST(null AS sql_identifier) AS character_set_name,
680679

681-
CAST(null AS sql_identifier) AS collation_catalog,
682-
CAST(null AS sql_identifier) AS collation_schema,
683-
CAST(null AS sql_identifier) AS collation_name,
680+
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
681+
CAST(nco.nspname AS sql_identifier) AS collation_schema,
682+
CAST(co.collname AS sql_identifier) AS collation_name,
684683

685684
CAST(CASE WHEN t.typtype = 'd' THEN current_database() ELSE null END
686685
AS sql_identifier) AS domain_catalog,
@@ -718,16 +717,15 @@ CREATE VIEW columns AS
718717
AND EXISTS (SELECT 1 FROM pg_rewrite WHERE ev_class = c.oid AND ev_type = '4' AND is_instead))
719718
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_updatable
720719

721-
FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum),
722-
pg_class c, pg_namespace nc,
723-
(pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid))
724-
LEFT JOIN (pg_type bt JOIN pg_namespace nbt ON (bt.typnamespace = nbt.oid))
720+
FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON attrelid = adrelid AND attnum = adnum)
721+
JOIN (pg_class c JOIN pg_namespace nc ON (c.relnamespace = nc.oid)) ON a.attrelid = c.oid
722+
JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON a.atttypid = t.oid
723+
LEFT JOIN (pg_type bt JOIN pg_namespace nbt ON (bt.typnamespace = nbt.oid))
725724
ON (t.typtype = 'd' AND t.typbasetype = bt.oid)
725+
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
726+
ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
726727

727-
WHERE a.attrelid = c.oid
728-
AND a.atttypid = t.oid
729-
AND nc.oid = c.relnamespace
730-
AND (NOT pg_is_other_temp_schema(nc.oid))
728+
WHERE (NOT pg_is_other_temp_schema(nc.oid))
731729

732730
AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f')
733731

@@ -914,9 +912,9 @@ CREATE VIEW domains AS
914912
CAST(null AS sql_identifier) AS character_set_schema,
915913
CAST(null AS sql_identifier) AS character_set_name,
916914

917-
CAST(null AS sql_identifier) AS collation_catalog,
918-
CAST(null AS sql_identifier) AS collation_schema,
919-
CAST(null AS sql_identifier) AS collation_name,
915+
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
916+
CAST(nco.nspname AS sql_identifier) AS collation_schema,
917+
CAST(co.collname AS sql_identifier) AS collation_name,
920918

921919
CAST(
922920
_pg_numeric_precision(t.typbasetype, t.typtypmod)
@@ -954,13 +952,13 @@ CREATE VIEW domains AS
954952
CAST(null AS cardinal_number) AS maximum_cardinality,
955953
CAST(1 AS sql_identifier) AS dtd_identifier
956954

957-
FROM pg_type t, pg_namespace nt,
958-
pg_type bt, pg_namespace nbt
955+
FROM (pg_type t JOIN pg_namespace nt ON t.typnamespace = nt.oid)
956+
JOIN (pg_type bt JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid)
957+
ON (t.typbasetype = bt.oid AND t.typtype = 'd')
958+
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
959+
ON t.typcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
959960

960-
WHERE t.typnamespace = nt.oid
961-
AND t.typbasetype = bt.oid
962-
AND bt.typnamespace = nbt.oid
963-
AND t.typtype = 'd';
961+
;
964962

965963
GRANT SELECT ON domains TO PUBLIC;
966964

@@ -1515,7 +1513,7 @@ CREATE TABLE sql_implementation_info (
15151513
) WITHOUT OIDS;
15161514

15171515
INSERT INTO sql_implementation_info VALUES ('10003', 'CATALOG NAME', NULL, 'Y', NULL);
1518-
INSERT INTO sql_implementation_info VALUES ('10004', 'COLLATING SEQUENCE', NULL, '', 'not supported');
1516+
INSERT INTO sql_implementation_info VALUES ('10004', 'COLLATING SEQUENCE', NULL, (SELECT default_collate_name FROM character_sets), NULL);
15191517
INSERT INTO sql_implementation_info VALUES ('23', 'CURSOR COMMIT BEHAVIOR', 1, NULL, 'close cursors and retain prepared statements');
15201518
INSERT INTO sql_implementation_info VALUES ('2', 'DATA SOURCE NAME', NULL, '', NULL);
15211519
INSERT INTO sql_implementation_info VALUES ('17', 'DBMS NAME', NULL, (select trim(trailing ' ' from substring(version() from '^[^0-9]*'))), NULL);
@@ -2442,9 +2440,9 @@ CREATE VIEW element_types AS
24422440
CAST(null AS sql_identifier) AS character_set_catalog,
24432441
CAST(null AS sql_identifier) AS character_set_schema,
24442442
CAST(null AS sql_identifier) AS character_set_name,
2445-
CAST(null AS sql_identifier) AS collation_catalog,
2446-
CAST(null AS sql_identifier) AS collation_schema,
2447-
CAST(null AS sql_identifier) AS collation_name,
2443+
CAST(CASE WHEN nco.nspname IS NOT NULL THEN current_database() END AS sql_identifier) AS collation_catalog,
2444+
CAST(nco.nspname AS sql_identifier) AS collation_schema,
2445+
CAST(co.collname AS sql_identifier) AS collation_name,
24482446
CAST(null AS cardinal_number) AS numeric_precision,
24492447
CAST(null AS cardinal_number) AS numeric_precision_radix,
24502448
CAST(null AS cardinal_number) AS numeric_scale,
@@ -2470,7 +2468,7 @@ CREATE VIEW element_types AS
24702468
/* columns, attributes */
24712469
SELECT c.relnamespace, CAST(c.relname AS sql_identifier),
24722470
CASE WHEN c.relkind = 'c' THEN 'USER-DEFINED TYPE'::text ELSE 'TABLE'::text END,
2473-
a.attnum, a.atttypid
2471+
a.attnum, a.atttypid, a.attcollation
24742472
FROM pg_class c, pg_attribute a
24752473
WHERE c.oid = a.attrelid
24762474
AND c.relkind IN ('r', 'v', 'f', 'c')
@@ -2480,15 +2478,15 @@ CREATE VIEW element_types AS
24802478

24812479
/* domains */
24822480
SELECT t.typnamespace, CAST(t.typname AS sql_identifier),
2483-
'DOMAIN'::text, 1, t.typbasetype
2481+
'DOMAIN'::text, 1, t.typbasetype, t.typcollation
24842482
FROM pg_type t
24852483
WHERE t.typtype = 'd'
24862484

24872485
UNION ALL
24882486

24892487
/* parameters */
24902488
SELECT pronamespace, CAST(proname || '_' || CAST(oid AS text) AS sql_identifier),
2491-
'ROUTINE'::text, (ss.x).n, (ss.x).x
2489+
'ROUTINE'::text, (ss.x).n, (ss.x).x, 0
24922490
FROM (SELECT p.pronamespace, p.proname, p.oid,
24932491
_pg_expandarray(coalesce(p.proallargtypes, p.proargtypes::oid[])) AS x
24942492
FROM pg_proc p) AS ss
@@ -2497,10 +2495,12 @@ CREATE VIEW element_types AS
24972495

24982496
/* result types */
24992497
SELECT p.pronamespace, CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier),
2500-
'ROUTINE'::text, 0, p.prorettype
2498+
'ROUTINE'::text, 0, p.prorettype, 0
25012499
FROM pg_proc p
25022500

2503-
) AS x (objschema, objname, objtype, objdtdid, objtypeid)
2501+
) AS x (objschema, objname, objtype, objdtdid, objtypeid, objcollation)
2502+
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON (co.collnamespace = nco.oid))
2503+
ON x.objcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
25042504

25052505
WHERE n.oid = x.objschema
25062506
AND at.oid = x.objtypeid

0 commit comments

Comments
 (0)