Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 44430db

Browse files
committed
Fix bugs in referential_constraints view.
1 parent 4a48c67 commit 44430db

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

doc/src/sgml/information_schema.sgml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/information_schema.sgml,v 1.9 2003/09/20 20:12:05 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/information_schema.sgml,v 1.10 2003/10/16 23:46:17 petere Exp $ -->
22

33
<chapter id="information-schema">
44
<title>The Information Schema</title>
@@ -2146,7 +2146,7 @@ ORDER BY c.ordinal_position;
21462146
<entry>
21472147
Update rule of the foreign key constraint:
21482148
<literal>CASCADE</literal>, <literal>SET NULL</literal>,
2149-
<literal>SET DEFAULT</literal>, <literal>RESTRICT</literal>,or
2149+
<literal>SET DEFAULT</literal>, <literal>RESTRICT</literal>, or
21502150
<literal>NO ACTION</literal>.
21512151
</entry>
21522152
</row>
@@ -2157,7 +2157,7 @@ ORDER BY c.ordinal_position;
21572157
<entry>
21582158
Delete rule of the foreign key constraint:
21592159
<literal>CASCADE</literal>, <literal>SET NULL</literal>,
2160-
<literal>SET DEFAULT</literal>, <literal>RESTRICT</literal>,or
2160+
<literal>SET DEFAULT</literal>, <literal>RESTRICT</literal>, or
21612161
<literal>NO ACTION</literal>.
21622162
</entry>
21632163
</row>

src/backend/catalog/information_schema.sql

+28-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright 2003, PostgreSQL Global Development Group
66
*
7-
* $Id: information_schema.sql,v 1.12 2003/06/29 15:14:41 petere Exp $
7+
* $Id: information_schema.sql,v 1.13 2003/10/16 23:46:17 petere Exp $
88
*/
99

1010
/*
@@ -747,11 +747,26 @@ GRANT SELECT ON parameters TO PUBLIC;
747747
* REFERENTIAL_CONSTRAINTS view
748748
*/
749749

750+
CREATE FUNCTION _pg_keyissubset(smallint[], smallint[]) RETURNS boolean
751+
LANGUAGE sql
752+
IMMUTABLE
753+
RETURNS NULL ON NULL INPUT
754+
AS 'select $1[1] is null or ($1[1] = any ($2) and coalesce(_pg_keyissubset($1[2:array_upper($1,1)], $2), true))';
755+
756+
CREATE FUNCTION _pg_keysequal(smallint[], smallint[]) RETURNS boolean
757+
LANGUAGE sql
758+
IMMUTABLE
759+
RETURNS NULL ON NULL INPUT
760+
AS 'select _pg_keyissubset($1, $2) and _pg_keyissubset($2, $1)';
761+
750762
CREATE VIEW referential_constraints AS
751763
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
752764
CAST(ncon.nspname AS sql_identifier) AS constraint_schema,
753765
CAST(con.conname AS sql_identifier) AS constraint_name,
754-
CAST(current_database() AS sql_identifier) AS unique_constraint_catalog,
766+
CAST(
767+
CASE WHEN npkc.nspname IS NULL THEN NULL
768+
ELSE current_database() END
769+
AS sql_identifier) AS unique_constraint_catalog,
755770
CAST(npkc.nspname AS sql_identifier) AS unique_constraint_schema,
756771
CAST(pkc.conname AS sql_identifier) AS unique_constraint_name,
757772

@@ -766,30 +781,27 @@ CREATE VIEW referential_constraints AS
766781
WHEN 'n' THEN 'SET NULL'
767782
WHEN 'd' THEN 'SET DEFAULT'
768783
WHEN 'r' THEN 'RESTRICT'
769-
WHEN 'a' THEN 'NOACTION' END
784+
WHEN 'a' THEN 'NO ACTION' END
770785
AS character_data) AS update_rule,
771786

772787
CAST(
773788
CASE con.confdeltype WHEN 'c' THEN 'CASCADE'
774789
WHEN 'n' THEN 'SET NULL'
775790
WHEN 'd' THEN 'SET DEFAULT'
776791
WHEN 'r' THEN 'RESTRICT'
777-
WHEN 'a' THEN 'NOACTION' END
792+
WHEN 'a' THEN 'NO ACTION' END
778793
AS character_data) AS delete_rule
779794

780-
FROM pg_namespace ncon,
781-
pg_constraint con,
782-
pg_class c,
783-
pg_constraint pkc,
784-
pg_namespace npkc,
785-
pg_user u
795+
FROM (pg_namespace ncon INNER JOIN pg_constraint con ON ncon.oid = con.connamespace
796+
INNER JOIN pg_class c ON con.conrelid = c.oid
797+
INNER JOIN pg_user u ON c.relowner = u.usesysid)
798+
LEFT JOIN
799+
(pg_constraint pkc INNER JOIN pg_namespace npkc ON pkc.connamespace = npkc.oid)
800+
ON con.confrelid = pkc.conrelid AND _pg_keysequal(con.confkey, pkc.conkey)
786801

787-
WHERE ncon.oid = con.connamespace
788-
AND con.conrelid = c.oid
789-
AND con.confkey = pkc.conkey
790-
AND pkc.connamespace = npkc.oid
791-
AND c.relowner = u.usesysid
792-
AND c.relkind = 'r'
802+
WHERE c.relkind = 'r'
803+
AND con.contype = 'f'
804+
AND (pkc.contype IN ('p', 'u') OR pkc.contype IS NULL)
793805
AND u.usename = current_user;
794806

795807
GRANT SELECT ON referential_constraints TO PUBLIC;

0 commit comments

Comments
 (0)