Skip to content

Commit 44839ac

Browse files
committed
Fix information_schema.key_column_usage to show correct value of
position_in_unique_constraint (column newly added per SQL2003). Greg Mullane
1 parent 5a248cd commit 44839ac

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/backend/catalog/information_schema.sql

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2003-2006, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.34 2006/09/04 21:03:18 momjian Exp $
7+
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.35 2006/09/04 23:13:01 tgl Exp $
88
*/
99

1010
/*
@@ -921,11 +921,18 @@ CREATE VIEW key_column_usage AS
921921
CAST(relname AS sql_identifier) AS table_name,
922922
CAST(a.attname AS sql_identifier) AS column_name,
923923
CAST((ss.x).n AS cardinal_number) AS ordinal_position,
924-
CAST(null AS cardinal_number) AS position_in_unique_constraint -- FIXME
924+
(
925+
SELECT CAST(a AS cardinal_number)
926+
FROM pg_constraint,
927+
(SELECT a FROM generate_series(1, array_upper(ss.confkey,1)) a) AS foo
928+
WHERE conrelid = ss.confrelid
929+
AND conkey[foo.a] = ss.confkey[(ss.x).n]
930+
) AS position_in_unique_constraint
925931
FROM pg_attribute a,
926-
(SELECT r.oid, nc.nspname AS nc_nspname, c.conname,
927-
nr.nspname AS nr_nspname, r.relname,
928-
_pg_expandarray(c.conkey) AS x
932+
(SELECT r.oid, r.relname, nc.nspname AS nc_nspname,
933+
nr.nspname AS nr_nspname,
934+
c.conname, c.confkey, c.confrelid,
935+
_pg_expandarray(c.conkey) AS x
929936
FROM pg_namespace nr, pg_class r, pg_namespace nc,
930937
pg_constraint c
931938
WHERE nr.oid = r.relnamespace

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy