4
4
*
5
5
* Copyright 2003, PostgreSQL Global Development Group
6
6
*
7
- * $Id: information_schema.sql,v 1.14 2003/10/18 12:53:35 petere Exp $
7
+ * $Id: information_schema.sql,v 1.15 2003/10/18 19:06:10 tgl Exp $
8
8
*/
9
9
10
10
/*
@@ -178,7 +178,10 @@ CREATE VIEW column_privileges AS
178
178
UNION ALL
179
179
SELECT 0 , 0 , ' PUBLIC'
180
180
) AS grantee (usesysid, grosysid, name),
181
- (SELECT ' SELECT' UNION ALL SELECT ' INSERT' UNION ALL SELECT ' UPDATE' UNION ALL SELECT ' REFERENCES' ) AS pr (type)
181
+ (SELECT ' SELECT' UNION ALL
182
+ SELECT ' INSERT' UNION ALL
183
+ SELECT ' UPDATE' UNION ALL
184
+ SELECT ' REFERENCES' ) AS pr (type)
182
185
183
186
WHERE a .attrelid = c .oid
184
187
AND c .relnamespace = nc .oid
@@ -389,6 +392,22 @@ GRANT SELECT ON columns TO PUBLIC;
389
392
* CONSTRAINT_COLUMN_USAGE view
390
393
*/
391
394
395
+ /* This returns the integers from 1 to INDEX_MAX_KEYS/FUNC_MAX_ARGS */
396
+ CREATE FUNCTION _pg_keypositions () RETURNS SETOF integer
397
+ LANGUAGE sql
398
+ IMMUTABLE
399
+ AS ' select 1 union all select 2 union all select 3 union all
400
+ select 4 union all select 5 union all select 6 union all
401
+ select 7 union all select 8 union all select 9 union all
402
+ select 10 union all select 11 union all select 12 union all
403
+ select 13 union all select 14 union all select 15 union all
404
+ select 16 union all select 17 union all select 18 union all
405
+ select 19 union all select 20 union all select 21 union all
406
+ select 22 union all select 23 union all select 24 union all
407
+ select 25 union all select 26 union all select 27 union all
408
+ select 28 union all select 29 union all select 30 union all
409
+ select 31 union all select 32' ;
410
+
392
411
CREATE VIEW constraint_column_usage AS
393
412
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
394
413
CAST(tblschema AS sql_identifier) AS table_schema,
@@ -419,14 +438,8 @@ CREATE VIEW constraint_column_usage AS
419
438
420
439
/* unique/primary key/foreign key constraints */
421
440
SELECT nr .nspname , r .relname , r .relowner , a .attname , nc .nspname , c .conname
422
- FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc, pg_constraint c,
423
- (select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all
424
- select 6 union all select 7 union all select 8 union all select 9 union all select 10 union all
425
- select 11 union all select 12 union all select 13 union all select 14 union all select 15 union all
426
- select 16 union all select 17 union all select 18 union all select 19 union all select 20 union all
427
- select 21 union all select 22 union all select 23 union all select 24 union all select 25 union all
428
- select 26 union all select 27 union all select 28 union all select 29 union all select 30 union all
429
- select 31 union all select 32 ) AS pos(n)
441
+ FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc,
442
+ pg_constraint c, _pg_keypositions() AS pos(n)
430
443
WHERE nr .oid = r .relnamespace
431
444
AND r .oid = a .attrelid
432
445
AND r .oid = c .conrelid
@@ -659,16 +672,8 @@ CREATE VIEW key_column_usage AS
659
672
CAST(a .attname AS sql_identifier) AS column_name,
660
673
CAST(pos .n AS cardinal_number) AS ordinal_position
661
674
662
- FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc, pg_constraint c,
663
- pg_user u,
664
- (select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all
665
- select 6 union all select 7 union all select 8 union all select 9 union all select 10 union all
666
- select 11 union all select 12 union all select 13 union all select 14 union all select 15 union all
667
- select 16 union all select 17 union all select 18 union all select 19 union all select 20 union all
668
- select 21 union all select 22 union all select 23 union all select 24 union all select 25 union all
669
- select 26 union all select 27 union all select 28 union all select 29 union all select 30 union all
670
- select 31 union all select 32 ) AS pos(n)
671
-
675
+ FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc,
676
+ pg_constraint c, pg_user u, _pg_keypositions() AS pos(n)
672
677
WHERE nr .oid = r .relnamespace
673
678
AND r .oid = a .attrelid
674
679
AND r .oid = c .conrelid
@@ -693,7 +698,7 @@ CREATE VIEW parameters AS
693
698
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
694
699
CAST(n .nspname AS sql_identifier) AS specific_schema,
695
700
CAST(p .proname || ' _' || CAST(p .oid AS text ) AS sql_identifier) AS specific_name,
696
- CAST(n + 1 AS cardinal_number) AS ordinal_position,
701
+ CAST(pos . n AS cardinal_number) AS ordinal_position,
697
702
CAST(' IN' AS character_data) AS parameter_mode,
698
703
CAST(' NO' AS character_data) AS is_result,
699
704
CAST(' NO' AS character_data) AS as_locator,
@@ -724,19 +729,13 @@ CREATE VIEW parameters AS
724
729
CAST(null AS sql_identifier) AS scope_schema,
725
730
CAST(null AS sql_identifier) AS scope_name,
726
731
CAST(null AS cardinal_number) AS maximum_cardinality,
727
- CAST(n + 1 AS sql_identifier) AS dtd_identifier
732
+ CAST(pos . n AS sql_identifier) AS dtd_identifier
728
733
729
734
FROM pg_namespace n, pg_proc p, pg_type t, pg_namespace nt, pg_user u,
730
- (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all
731
- select 5 union all select 6 union all select 7 union all select 8 union all select 9 union all
732
- select 10 union all select 11 union all select 12 union all select 13 union all select 14 union all
733
- select 15 union all select 16 union all select 17 union all select 18 union all select 19 union all
734
- select 20 union all select 21 union all select 22 union all select 23 union all select 24 union all
735
- select 25 union all select 26 union all select 27 union all select 28 union all select 29 union all
736
- select 30 union all select 31 ) AS pos(n)
737
-
738
- WHERE n .oid = p .pronamespace AND p .pronargs > pos .n
739
- AND p .proargtypes [n] = t .oid AND t .typnamespace = nt .oid
735
+ _pg_keypositions() AS pos(n)
736
+
737
+ WHERE n .oid = p .pronamespace AND p .pronargs >= pos .n
738
+ AND p .proargtypes [pos .n - 1 ] = t .oid AND t .typnamespace = nt .oid
740
739
AND p .proowner = u .usesysid
741
740
AND (u .usename = current_user OR has_function_privilege(p .oid , ' EXECUTE' ));
742
741
@@ -752,7 +751,7 @@ CREATE FUNCTION _pg_keyissubset(smallint[], smallint[]) RETURNS boolean
752
751
LANGUAGE sql
753
752
IMMUTABLE
754
753
RETURNS NULL ON NULL INPUT
755
- AS ' select $1[1] is null or ($1[1] = any ($2) and coalesce(information_schema._pg_keyissubset($1[2:array_upper($1,1)], $2), true))' ;
754
+ AS ' select $1[1] is null or ($1[1] = any ($2) and coalesce(information_schema._pg_keyissubset($1[2:pg_catalog. array_upper($1,1)], $2), true))' ;
756
755
757
756
CREATE FUNCTION _pg_keysequal (smallint [], smallint []) RETURNS boolean
758
757
LANGUAGE sql
@@ -831,7 +830,10 @@ CREATE VIEW role_column_grants AS
831
830
pg_namespace nc,
832
831
pg_user u_grantor,
833
832
pg_group g_grantee,
834
- (SELECT ' SELECT' UNION ALL SELECT ' INSERT' UNION ALL SELECT ' UPDATE' UNION ALL SELECT ' REFERENCES' ) AS pr (type)
833
+ (SELECT ' SELECT' UNION ALL
834
+ SELECT ' INSERT' UNION ALL
835
+ SELECT ' UPDATE' UNION ALL
836
+ SELECT ' REFERENCES' ) AS pr (type)
835
837
836
838
WHERE a .attrelid = c .oid
837
839
AND c .relnamespace = nc .oid
@@ -900,8 +902,13 @@ CREATE VIEW role_table_grants AS
900
902
pg_namespace nc,
901
903
pg_user u_grantor,
902
904
pg_group g_grantee,
903
- (SELECT ' SELECT' UNION ALL SELECT ' DELETE' UNION ALL SELECT ' INSERT' UNION ALL SELECT ' UPDATE'
904
- UNION ALL SELECT ' REFERENCES' UNION ALL SELECT ' RULE' UNION ALL SELECT ' TRIGGER' ) AS pr (type)
905
+ (SELECT ' SELECT' UNION ALL
906
+ SELECT ' DELETE' UNION ALL
907
+ SELECT ' INSERT' UNION ALL
908
+ SELECT ' UPDATE' UNION ALL
909
+ SELECT ' REFERENCES' UNION ALL
910
+ SELECT ' RULE' UNION ALL
911
+ SELECT ' TRIGGER' ) AS pr (type)
905
912
906
913
WHERE c .relnamespace = nc .oid
907
914
AND c .relkind IN (' r' , ' v' )
@@ -1310,8 +1317,13 @@ CREATE VIEW table_privileges AS
1310
1317
UNION ALL
1311
1318
SELECT 0 , 0 , ' PUBLIC'
1312
1319
) AS grantee (usesysid, grosysid, name),
1313
- (SELECT ' SELECT' UNION ALL SELECT ' DELETE' UNION ALL SELECT ' INSERT' UNION ALL SELECT ' UPDATE'
1314
- UNION ALL SELECT ' REFERENCES' UNION ALL SELECT ' RULE' UNION ALL SELECT ' TRIGGER' ) AS pr (type)
1320
+ (SELECT ' SELECT' UNION ALL
1321
+ SELECT ' DELETE' UNION ALL
1322
+ SELECT ' INSERT' UNION ALL
1323
+ SELECT ' UPDATE' UNION ALL
1324
+ SELECT ' REFERENCES' UNION ALL
1325
+ SELECT ' RULE' UNION ALL
1326
+ SELECT ' TRIGGER' ) AS pr (type)
1315
1327
1316
1328
WHERE c .relnamespace = nc .oid
1317
1329
AND c .relkind IN (' r' , ' v' )
@@ -1414,7 +1426,9 @@ CREATE VIEW triggers AS
1414
1426
CAST(null AS sql_identifier) AS condition_reference_new_table
1415
1427
1416
1428
FROM pg_namespace n, pg_class c, pg_trigger t, pg_user u,
1417
- (SELECT 4 , ' INSERT' UNION ALL SELECT 8 , ' DELETE' UNION ALL SELECT 16 , ' UPDATE' ) AS em (num, text )
1429
+ (SELECT 4 , ' INSERT' UNION ALL
1430
+ SELECT 8 , ' DELETE' UNION ALL
1431
+ SELECT 16 , ' UPDATE' ) AS em (num, text )
1418
1432
1419
1433
WHERE n .oid = c .relnamespace
1420
1434
AND c .oid = t .tgrelid
@@ -1640,7 +1654,8 @@ CREATE VIEW element_types AS
1640
1654
FROM pg_namespace n, pg_type at, pg_namespace nbt, pg_type bt,
1641
1655
(
1642
1656
/* columns */
1643
- SELECT c .relnamespace , c .relname , ' TABLE' ::text , a .attnum , a .atttypid
1657
+ SELECT c .relnamespace , CAST(c .relname AS sql_identifier),
1658
+ ' TABLE' ::text , a .attnum , a .atttypid
1644
1659
FROM pg_class c, pg_attribute a
1645
1660
WHERE c .oid = a .attrelid
1646
1661
AND c .relkind IN (' r' , ' v' )
@@ -1649,28 +1664,24 @@ CREATE VIEW element_types AS
1649
1664
UNION ALL
1650
1665
1651
1666
/* domains */
1652
- SELECT t .typnamespace , t .typname , ' DOMAIN' ::text , 1 , t .typbasetype
1667
+ SELECT t .typnamespace , CAST(t .typname AS sql_identifier),
1668
+ ' DOMAIN' ::text , 1 , t .typbasetype
1653
1669
FROM pg_type t
1654
1670
WHERE t .typtype = ' d'
1655
1671
1656
1672
UNION ALL
1657
1673
1658
1674
/* parameters */
1659
- SELECT p .pronamespace , p .proname , ' ROUTINE' ::text , pos .n + 1 , p .proargtypes [n]
1660
- FROM pg_proc p,
1661
- (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all
1662
- select 5 union all select 6 union all select 7 union all select 8 union all select 9 union all
1663
- select 10 union all select 11 union all select 12 union all select 13 union all select 14 union all
1664
- select 15 union all select 16 union all select 17 union all select 18 union all select 19 union all
1665
- select 20 union all select 21 union all select 22 union all select 23 union all select 24 union all
1666
- select 25 union all select 26 union all select 27 union all select 28 union all select 29 union all
1667
- select 30 union all select 31 ) AS pos(n)
1668
- WHERE p .pronargs > pos .n
1675
+ SELECT p .pronamespace , CAST(p .proname || ' _' || CAST(p .oid AS text ) AS sql_identifier),
1676
+ ' ROUTINE' ::text , pos .n , p .proargtypes [pos .n - 1 ]
1677
+ FROM pg_proc p, _pg_keypositions() AS pos(n)
1678
+ WHERE p .pronargs >= pos .n
1669
1679
1670
1680
UNION ALL
1671
1681
1672
1682
/* result types */
1673
- SELECT p .pronamespace , p .proname , ' ROUTINE' ::text , 0 , p .prorettype
1683
+ SELECT p .pronamespace , CAST(p .proname || ' _' || CAST(p .oid AS text ) AS sql_identifier),
1684
+ ' ROUTINE' ::text , 0 , p .prorettype
1674
1685
FROM pg_proc p
1675
1686
1676
1687
) AS x (objschema, objname, objtype, objdtdid, objtypeid)
0 commit comments