Commit e341cdb0 authored by Tom Lane's avatar Tom Lane

Further work on information_schema. _pg_keyissubset() wasn't quite

fully search-path-proof yet; also, element_types view did not work for
parameters and result types of functions, because it didn't generate
the object_name for the function the same way the data_type_privileges
view does.  While at it, centralize dependencies on INDEX_MAX_KEYS/
FUNC_MAX_ARGS into a function returning setof int, so that it will be
easier to fix information_schema for nonstandard values of these
parameters.
parent eda80f09
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Copyright 2003, PostgreSQL Global Development Group * Copyright 2003, PostgreSQL Global Development Group
* *
* $Id: information_schema.sql,v 1.14 2003/10/18 12:53:35 petere Exp $ * $Id: information_schema.sql,v 1.15 2003/10/18 19:06:10 tgl Exp $
*/ */
/* /*
...@@ -178,7 +178,10 @@ CREATE VIEW column_privileges AS ...@@ -178,7 +178,10 @@ CREATE VIEW column_privileges AS
UNION ALL UNION ALL
SELECT 0, 0, 'PUBLIC' SELECT 0, 0, 'PUBLIC'
) AS grantee (usesysid, grosysid, name), ) AS grantee (usesysid, grosysid, name),
(SELECT 'SELECT' UNION ALL SELECT 'INSERT' UNION ALL SELECT 'UPDATE' UNION ALL SELECT 'REFERENCES') AS pr (type) (SELECT 'SELECT' UNION ALL
SELECT 'INSERT' UNION ALL
SELECT 'UPDATE' UNION ALL
SELECT 'REFERENCES') AS pr (type)
WHERE a.attrelid = c.oid WHERE a.attrelid = c.oid
AND c.relnamespace = nc.oid AND c.relnamespace = nc.oid
...@@ -389,6 +392,22 @@ GRANT SELECT ON columns TO PUBLIC; ...@@ -389,6 +392,22 @@ GRANT SELECT ON columns TO PUBLIC;
* CONSTRAINT_COLUMN_USAGE view * CONSTRAINT_COLUMN_USAGE view
*/ */
/* This returns the integers from 1 to INDEX_MAX_KEYS/FUNC_MAX_ARGS */
CREATE FUNCTION _pg_keypositions() RETURNS SETOF integer
LANGUAGE sql
IMMUTABLE
AS 'select 1 union all select 2 union all select 3 union all
select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9 union all
select 10 union all select 11 union all select 12 union all
select 13 union all select 14 union all select 15 union all
select 16 union all select 17 union all select 18 union all
select 19 union all select 20 union all select 21 union all
select 22 union all select 23 union all select 24 union all
select 25 union all select 26 union all select 27 union all
select 28 union all select 29 union all select 30 union all
select 31 union all select 32';
CREATE VIEW constraint_column_usage AS CREATE VIEW constraint_column_usage AS
SELECT CAST(current_database() AS sql_identifier) AS table_catalog, SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
CAST(tblschema AS sql_identifier) AS table_schema, CAST(tblschema AS sql_identifier) AS table_schema,
...@@ -419,14 +438,8 @@ CREATE VIEW constraint_column_usage AS ...@@ -419,14 +438,8 @@ CREATE VIEW constraint_column_usage AS
/* unique/primary key/foreign key constraints */ /* unique/primary key/foreign key constraints */
SELECT nr.nspname, r.relname, r.relowner, a.attname, nc.nspname, c.conname SELECT nr.nspname, r.relname, r.relowner, a.attname, nc.nspname, c.conname
FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc, pg_constraint c, FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc,
(select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all pg_constraint c, _pg_keypositions() AS pos(n)
select 6 union all select 7 union all select 8 union all select 9 union all select 10 union all
select 11 union all select 12 union all select 13 union all select 14 union all select 15 union all
select 16 union all select 17 union all select 18 union all select 19 union all select 20 union all
select 21 union all select 22 union all select 23 union all select 24 union all select 25 union all
select 26 union all select 27 union all select 28 union all select 29 union all select 30 union all
select 31 union all select 32) AS pos(n)
WHERE nr.oid = r.relnamespace WHERE nr.oid = r.relnamespace
AND r.oid = a.attrelid AND r.oid = a.attrelid
AND r.oid = c.conrelid AND r.oid = c.conrelid
...@@ -659,16 +672,8 @@ CREATE VIEW key_column_usage AS ...@@ -659,16 +672,8 @@ CREATE VIEW key_column_usage AS
CAST(a.attname AS sql_identifier) AS column_name, CAST(a.attname AS sql_identifier) AS column_name,
CAST(pos.n AS cardinal_number) AS ordinal_position CAST(pos.n AS cardinal_number) AS ordinal_position
FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc, pg_constraint c, FROM pg_namespace nr, pg_class r, pg_attribute a, pg_namespace nc,
pg_user u, pg_constraint c, pg_user u, _pg_keypositions() AS pos(n)
(select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all
select 6 union all select 7 union all select 8 union all select 9 union all select 10 union all
select 11 union all select 12 union all select 13 union all select 14 union all select 15 union all
select 16 union all select 17 union all select 18 union all select 19 union all select 20 union all
select 21 union all select 22 union all select 23 union all select 24 union all select 25 union all
select 26 union all select 27 union all select 28 union all select 29 union all select 30 union all
select 31 union all select 32) AS pos(n)
WHERE nr.oid = r.relnamespace WHERE nr.oid = r.relnamespace
AND r.oid = a.attrelid AND r.oid = a.attrelid
AND r.oid = c.conrelid AND r.oid = c.conrelid
...@@ -693,7 +698,7 @@ CREATE VIEW parameters AS ...@@ -693,7 +698,7 @@ CREATE VIEW parameters AS
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog, SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(n.nspname AS sql_identifier) AS specific_schema, CAST(n.nspname AS sql_identifier) AS specific_schema,
CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name, CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name,
CAST(n + 1 AS cardinal_number) AS ordinal_position, CAST(pos.n AS cardinal_number) AS ordinal_position,
CAST('IN' AS character_data) AS parameter_mode, CAST('IN' AS character_data) AS parameter_mode,
CAST('NO' AS character_data) AS is_result, CAST('NO' AS character_data) AS is_result,
CAST('NO' AS character_data) AS as_locator, CAST('NO' AS character_data) AS as_locator,
...@@ -724,19 +729,13 @@ CREATE VIEW parameters AS ...@@ -724,19 +729,13 @@ CREATE VIEW parameters AS
CAST(null AS sql_identifier) AS scope_schema, CAST(null AS sql_identifier) AS scope_schema,
CAST(null AS sql_identifier) AS scope_name, CAST(null AS sql_identifier) AS scope_name,
CAST(null AS cardinal_number) AS maximum_cardinality, CAST(null AS cardinal_number) AS maximum_cardinality,
CAST(n + 1 AS sql_identifier) AS dtd_identifier CAST(pos.n AS sql_identifier) AS dtd_identifier
FROM pg_namespace n, pg_proc p, pg_type t, pg_namespace nt, pg_user u, FROM pg_namespace n, pg_proc p, pg_type t, pg_namespace nt, pg_user u,
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all _pg_keypositions() AS pos(n)
select 5 union all select 6 union all select 7 union all select 8 union all select 9 union all
select 10 union all select 11 union all select 12 union all select 13 union all select 14 union all WHERE n.oid = p.pronamespace AND p.pronargs >= pos.n
select 15 union all select 16 union all select 17 union all select 18 union all select 19 union all AND p.proargtypes[pos.n-1] = t.oid AND t.typnamespace = nt.oid
select 20 union all select 21 union all select 22 union all select 23 union all select 24 union all
select 25 union all select 26 union all select 27 union all select 28 union all select 29 union all
select 30 union all select 31) AS pos(n)
WHERE n.oid = p.pronamespace AND p.pronargs > pos.n
AND p.proargtypes[n] = t.oid AND t.typnamespace = nt.oid
AND p.proowner = u.usesysid AND p.proowner = u.usesysid
AND (u.usename = current_user OR has_function_privilege(p.oid, 'EXECUTE')); AND (u.usename = current_user OR has_function_privilege(p.oid, 'EXECUTE'));
...@@ -752,7 +751,7 @@ CREATE FUNCTION _pg_keyissubset(smallint[], smallint[]) RETURNS boolean ...@@ -752,7 +751,7 @@ CREATE FUNCTION _pg_keyissubset(smallint[], smallint[]) RETURNS boolean
LANGUAGE sql LANGUAGE sql
IMMUTABLE IMMUTABLE
RETURNS NULL ON NULL INPUT RETURNS NULL ON NULL INPUT
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))'; 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))';
CREATE FUNCTION _pg_keysequal(smallint[], smallint[]) RETURNS boolean CREATE FUNCTION _pg_keysequal(smallint[], smallint[]) RETURNS boolean
LANGUAGE sql LANGUAGE sql
...@@ -831,7 +830,10 @@ CREATE VIEW role_column_grants AS ...@@ -831,7 +830,10 @@ CREATE VIEW role_column_grants AS
pg_namespace nc, pg_namespace nc,
pg_user u_grantor, pg_user u_grantor,
pg_group g_grantee, pg_group g_grantee,
(SELECT 'SELECT' UNION ALL SELECT 'INSERT' UNION ALL SELECT 'UPDATE' UNION ALL SELECT 'REFERENCES') AS pr (type) (SELECT 'SELECT' UNION ALL
SELECT 'INSERT' UNION ALL
SELECT 'UPDATE' UNION ALL
SELECT 'REFERENCES') AS pr (type)
WHERE a.attrelid = c.oid WHERE a.attrelid = c.oid
AND c.relnamespace = nc.oid AND c.relnamespace = nc.oid
...@@ -900,8 +902,13 @@ CREATE VIEW role_table_grants AS ...@@ -900,8 +902,13 @@ CREATE VIEW role_table_grants AS
pg_namespace nc, pg_namespace nc,
pg_user u_grantor, pg_user u_grantor,
pg_group g_grantee, pg_group g_grantee,
(SELECT 'SELECT' UNION ALL SELECT 'DELETE' UNION ALL SELECT 'INSERT' UNION ALL SELECT 'UPDATE' (SELECT 'SELECT' UNION ALL
UNION ALL SELECT 'REFERENCES' UNION ALL SELECT 'RULE' UNION ALL SELECT 'TRIGGER') AS pr (type) SELECT 'DELETE' UNION ALL
SELECT 'INSERT' UNION ALL
SELECT 'UPDATE' UNION ALL
SELECT 'REFERENCES' UNION ALL
SELECT 'RULE' UNION ALL
SELECT 'TRIGGER') AS pr (type)
WHERE c.relnamespace = nc.oid WHERE c.relnamespace = nc.oid
AND c.relkind IN ('r', 'v') AND c.relkind IN ('r', 'v')
...@@ -1310,8 +1317,13 @@ CREATE VIEW table_privileges AS ...@@ -1310,8 +1317,13 @@ CREATE VIEW table_privileges AS
UNION ALL UNION ALL
SELECT 0, 0, 'PUBLIC' SELECT 0, 0, 'PUBLIC'
) AS grantee (usesysid, grosysid, name), ) AS grantee (usesysid, grosysid, name),
(SELECT 'SELECT' UNION ALL SELECT 'DELETE' UNION ALL SELECT 'INSERT' UNION ALL SELECT 'UPDATE' (SELECT 'SELECT' UNION ALL
UNION ALL SELECT 'REFERENCES' UNION ALL SELECT 'RULE' UNION ALL SELECT 'TRIGGER') AS pr (type) SELECT 'DELETE' UNION ALL
SELECT 'INSERT' UNION ALL
SELECT 'UPDATE' UNION ALL
SELECT 'REFERENCES' UNION ALL
SELECT 'RULE' UNION ALL
SELECT 'TRIGGER') AS pr (type)
WHERE c.relnamespace = nc.oid WHERE c.relnamespace = nc.oid
AND c.relkind IN ('r', 'v') AND c.relkind IN ('r', 'v')
...@@ -1414,7 +1426,9 @@ CREATE VIEW triggers AS ...@@ -1414,7 +1426,9 @@ CREATE VIEW triggers AS
CAST(null AS sql_identifier) AS condition_reference_new_table CAST(null AS sql_identifier) AS condition_reference_new_table
FROM pg_namespace n, pg_class c, pg_trigger t, pg_user u, FROM pg_namespace n, pg_class c, pg_trigger t, pg_user u,
(SELECT 4, 'INSERT' UNION ALL SELECT 8, 'DELETE' UNION ALL SELECT 16, 'UPDATE') AS em (num, text) (SELECT 4, 'INSERT' UNION ALL
SELECT 8, 'DELETE' UNION ALL
SELECT 16, 'UPDATE') AS em (num, text)
WHERE n.oid = c.relnamespace WHERE n.oid = c.relnamespace
AND c.oid = t.tgrelid AND c.oid = t.tgrelid
...@@ -1640,7 +1654,8 @@ CREATE VIEW element_types AS ...@@ -1640,7 +1654,8 @@ CREATE VIEW element_types AS
FROM pg_namespace n, pg_type at, pg_namespace nbt, pg_type bt, FROM pg_namespace n, pg_type at, pg_namespace nbt, pg_type bt,
( (
/* columns */ /* columns */
SELECT c.relnamespace, c.relname, 'TABLE'::text, a.attnum, a.atttypid SELECT c.relnamespace, CAST(c.relname AS sql_identifier),
'TABLE'::text, a.attnum, a.atttypid
FROM pg_class c, pg_attribute a FROM pg_class c, pg_attribute a
WHERE c.oid = a.attrelid WHERE c.oid = a.attrelid
AND c.relkind IN ('r', 'v') AND c.relkind IN ('r', 'v')
...@@ -1649,28 +1664,24 @@ CREATE VIEW element_types AS ...@@ -1649,28 +1664,24 @@ CREATE VIEW element_types AS
UNION ALL UNION ALL
/* domains */ /* domains */
SELECT t.typnamespace, t.typname, 'DOMAIN'::text, 1, t.typbasetype SELECT t.typnamespace, CAST(t.typname AS sql_identifier),
'DOMAIN'::text, 1, t.typbasetype
FROM pg_type t FROM pg_type t
WHERE t.typtype = 'd' WHERE t.typtype = 'd'
UNION ALL UNION ALL
/* parameters */ /* parameters */
SELECT p.pronamespace, p.proname, 'ROUTINE'::text, pos.n + 1, p.proargtypes[n] SELECT p.pronamespace, CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier),
FROM pg_proc p, 'ROUTINE'::text, pos.n, p.proargtypes[pos.n-1]
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all FROM pg_proc p, _pg_keypositions() AS pos(n)
select 5 union all select 6 union all select 7 union all select 8 union all select 9 union all WHERE p.pronargs >= pos.n
select 10 union all select 11 union all select 12 union all select 13 union all select 14 union all
select 15 union all select 16 union all select 17 union all select 18 union all select 19 union all
select 20 union all select 21 union all select 22 union all select 23 union all select 24 union all
select 25 union all select 26 union all select 27 union all select 28 union all select 29 union all
select 30 union all select 31) AS pos(n)
WHERE p.pronargs > pos.n
UNION ALL UNION ALL
/* result types */ /* result types */
SELECT p.pronamespace, p.proname, 'ROUTINE'::text, 0, p.prorettype SELECT p.pronamespace, CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier),
'ROUTINE'::text, 0, p.prorettype
FROM pg_proc p FROM pg_proc p
) AS x (objschema, objname, objtype, objdtdid, objtypeid) ) AS x (objschema, objname, objtype, objdtdid, objtypeid)
......
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