------+---------
(0 rows)
+SELECT ctid, ambuildempty
+FROM pg_catalog.pg_am fk
+WHERE ambuildempty != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_proc pk WHERE pk.oid = fk.ambuildempty);
+ ctid | ambuildempty
+------+--------------
+(0 rows)
+
SELECT ctid, ambulkdelete
FROM pg_catalog.pg_am fk
WHERE ambulkdelete != 0 AND
------+------------
(0 rows)
+SELECT ctid, amopsortfamily
+FROM pg_catalog.pg_amop fk
+WHERE amopsortfamily != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_opfamily pk WHERE pk.oid = fk.amopsortfamily);
+ ctid | amopsortfamily
+------+----------------
+(0 rows)
+
SELECT ctid, amprocfamily
FROM pg_catalog.pg_amproc fk
WHERE amprocfamily != 0 AND
------+----------
(0 rows)
+SELECT ctid, attcollation
+FROM pg_catalog.pg_attribute fk
+WHERE attcollation != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_collation pk WHERE pk.oid = fk.attcollation);
+ ctid | attcollation
+------+--------------
+(0 rows)
+
SELECT ctid, castsource
FROM pg_catalog.pg_cast fk
WHERE castsource != 0 AND
------+---------------
(0 rows)
+SELECT ctid, collnamespace
+FROM pg_catalog.pg_collation fk
+WHERE collnamespace != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_namespace pk WHERE pk.oid = fk.collnamespace);
+ ctid | collnamespace
+------+---------------
+(0 rows)
+
+SELECT ctid, collowner
+FROM pg_catalog.pg_collation fk
+WHERE collowner != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_authid pk WHERE pk.oid = fk.collowner);
+ ctid | collowner
+------+-----------
+(0 rows)
+
SELECT ctid, connamespace
FROM pg_catalog.pg_constraint fk
WHERE connamespace != 0 AND
------+----------
(0 rows)
+SELECT ctid, extowner
+FROM pg_catalog.pg_extension fk
+WHERE extowner != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_authid pk WHERE pk.oid = fk.extowner);
+ ctid | extowner
+------+----------
+(0 rows)
+
+SELECT ctid, extnamespace
+FROM pg_catalog.pg_extension fk
+WHERE extnamespace != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_namespace pk WHERE pk.oid = fk.extnamespace);
+ ctid | extnamespace
+------+--------------
+(0 rows)
+
SELECT ctid, indexrelid
FROM pg_catalog.pg_index fk
WHERE indexrelid != 0 AND
------+---------
(0 rows)
+SELECT ctid, provariadic
+FROM pg_catalog.pg_proc fk
+WHERE provariadic != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type pk WHERE pk.oid = fk.provariadic);
+ ctid | provariadic
+------+-------------
+(0 rows)
+
SELECT ctid, prorettype
FROM pg_catalog.pg_proc fk
WHERE prorettype != 0 AND
------+-------------
(0 rows)
+SELECT ctid, typcollation
+FROM pg_catalog.pg_type fk
+WHERE typcollation != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_collation pk WHERE pk.oid = fk.typcollation);
+ ctid | typcollation
+------+--------------
+(0 rows)
+
FROM pg_catalog.pg_am fk
WHERE ambuild != 0 AND
NOT EXISTS(SELECT 1 FROM pg_catalog.pg_proc pk WHERE pk.oid = fk.ambuild);
+SELECT ctid, ambuildempty
+FROM pg_catalog.pg_am fk
+WHERE ambuildempty != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_proc pk WHERE pk.oid = fk.ambuildempty);
SELECT ctid, ambulkdelete
FROM pg_catalog.pg_am fk
WHERE ambulkdelete != 0 AND
FROM pg_catalog.pg_amop fk
WHERE amopmethod != 0 AND
NOT EXISTS(SELECT 1 FROM pg_catalog.pg_am pk WHERE pk.oid = fk.amopmethod);
+SELECT ctid, amopsortfamily
+FROM pg_catalog.pg_amop fk
+WHERE amopsortfamily != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_opfamily pk WHERE pk.oid = fk.amopsortfamily);
SELECT ctid, amprocfamily
FROM pg_catalog.pg_amproc fk
WHERE amprocfamily != 0 AND
FROM pg_catalog.pg_attribute fk
WHERE atttypid != 0 AND
NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type pk WHERE pk.oid = fk.atttypid);
+SELECT ctid, attcollation
+FROM pg_catalog.pg_attribute fk
+WHERE attcollation != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_collation pk WHERE pk.oid = fk.attcollation);
SELECT ctid, castsource
FROM pg_catalog.pg_cast fk
WHERE castsource != 0 AND
FROM pg_catalog.pg_class fk
WHERE reltoastidxid != 0 AND
NOT EXISTS(SELECT 1 FROM pg_catalog.pg_class pk WHERE pk.oid = fk.reltoastidxid);
+SELECT ctid, collnamespace
+FROM pg_catalog.pg_collation fk
+WHERE collnamespace != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_namespace pk WHERE pk.oid = fk.collnamespace);
+SELECT ctid, collowner
+FROM pg_catalog.pg_collation fk
+WHERE collowner != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_authid pk WHERE pk.oid = fk.collowner);
SELECT ctid, connamespace
FROM pg_catalog.pg_constraint fk
WHERE connamespace != 0 AND
FROM pg_catalog.pg_description fk
WHERE classoid != 0 AND
NOT EXISTS(SELECT 1 FROM pg_catalog.pg_class pk WHERE pk.oid = fk.classoid);
+SELECT ctid, extowner
+FROM pg_catalog.pg_extension fk
+WHERE extowner != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_authid pk WHERE pk.oid = fk.extowner);
+SELECT ctid, extnamespace
+FROM pg_catalog.pg_extension fk
+WHERE extnamespace != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_namespace pk WHERE pk.oid = fk.extnamespace);
SELECT ctid, indexrelid
FROM pg_catalog.pg_index fk
WHERE indexrelid != 0 AND
FROM pg_catalog.pg_proc fk
WHERE prolang != 0 AND
NOT EXISTS(SELECT 1 FROM pg_catalog.pg_language pk WHERE pk.oid = fk.prolang);
+SELECT ctid, provariadic
+FROM pg_catalog.pg_proc fk
+WHERE provariadic != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type pk WHERE pk.oid = fk.provariadic);
SELECT ctid, prorettype
FROM pg_catalog.pg_proc fk
WHERE prorettype != 0 AND
FROM pg_catalog.pg_type fk
WHERE typbasetype != 0 AND
NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type pk WHERE pk.oid = fk.typbasetype);
+SELECT ctid, typcollation
+FROM pg_catalog.pg_type fk
+WHERE typcollation != 0 AND
+ NOT EXISTS(SELECT 1 FROM pg_catalog.pg_collation pk WHERE pk.oid = fk.typcollation);
be very slow.
Run on an empty database, it returns the system join relationships (shown
-below for 9.0devel). Note that unexpected matches may indicate bogus entries
+below for 9.1devel). Note that unexpected matches may indicate bogus entries
in system tables --- don't accept a peculiar match without question.
In particular, a field shown as joining to more than one target table is
-probably messed up. In 9.0devel, the *only* fields that should join to more
+probably messed up. In 9.1devel, the *only* fields that should join to more
than one target are pg_description.objoid, pg_depend.objid,
pg_depend.refobjid, pg_shdescription.objoid, pg_shdepend.objid, and
pg_shdepend.refobjid. (Running make_oidjoins_check is an easy way to spot
(Ideally we'd just regenerate the script as part of the regression
tests themselves, but that seems too slow...)
-NOTE: in 9.0devel, make_oidjoins_check produces two bogus join checks:
+NOTE: in 9.1devel, make_oidjoins_check produces two bogus join checks:
Join pg_catalog.pg_class.relfilenode => pg_catalog.pg_class.oid
Join pg_catalog.pg_database.datlastsysoid => pg_catalog.pg_database.oid
These are artifacts and should not be added to the oidjoins regress test.
Join pg_catalog.pg_am.ammarkpos => pg_catalog.pg_proc.oid
Join pg_catalog.pg_am.amrestrpos => pg_catalog.pg_proc.oid
Join pg_catalog.pg_am.ambuild => pg_catalog.pg_proc.oid
+Join pg_catalog.pg_am.ambuildempty => pg_catalog.pg_proc.oid
Join pg_catalog.pg_am.ambulkdelete => pg_catalog.pg_proc.oid
Join pg_catalog.pg_am.amvacuumcleanup => pg_catalog.pg_proc.oid
Join pg_catalog.pg_am.amcostestimate => pg_catalog.pg_proc.oid
Join pg_catalog.pg_amop.amoprighttype => pg_catalog.pg_type.oid
Join pg_catalog.pg_amop.amopopr => pg_catalog.pg_operator.oid
Join pg_catalog.pg_amop.amopmethod => pg_catalog.pg_am.oid
+Join pg_catalog.pg_amop.amopsortfamily => pg_catalog.pg_opfamily.oid
Join pg_catalog.pg_amproc.amprocfamily => pg_catalog.pg_opfamily.oid
Join pg_catalog.pg_amproc.amproclefttype => pg_catalog.pg_type.oid
Join pg_catalog.pg_amproc.amprocrighttype => pg_catalog.pg_type.oid
Join pg_catalog.pg_amproc.amproc => pg_catalog.pg_proc.oid
Join pg_catalog.pg_attribute.attrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_attribute.atttypid => pg_catalog.pg_type.oid
+Join pg_catalog.pg_attribute.attcollation => pg_catalog.pg_collation.oid
Join pg_catalog.pg_cast.castsource => pg_catalog.pg_type.oid
Join pg_catalog.pg_cast.casttarget => pg_catalog.pg_type.oid
Join pg_catalog.pg_cast.castfunc => pg_catalog.pg_proc.oid
Join pg_catalog.pg_class.reltablespace => pg_catalog.pg_tablespace.oid
Join pg_catalog.pg_class.reltoastrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_class.reltoastidxid => pg_catalog.pg_class.oid
+Join pg_catalog.pg_collation.collnamespace => pg_catalog.pg_namespace.oid
+Join pg_catalog.pg_collation.collowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_constraint.connamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_constraint.contypid => pg_catalog.pg_type.oid
Join pg_catalog.pg_conversion.connamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_depend.classid => pg_catalog.pg_class.oid
Join pg_catalog.pg_depend.refclassid => pg_catalog.pg_class.oid
Join pg_catalog.pg_description.classoid => pg_catalog.pg_class.oid
+Join pg_catalog.pg_extension.extowner => pg_catalog.pg_authid.oid
+Join pg_catalog.pg_extension.extnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_index.indexrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_index.indrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_language.lanowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_proc.pronamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_proc.proowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_proc.prolang => pg_catalog.pg_language.oid
+Join pg_catalog.pg_proc.provariadic => pg_catalog.pg_type.oid
Join pg_catalog.pg_proc.prorettype => pg_catalog.pg_type.oid
Join pg_catalog.pg_rewrite.ev_class => pg_catalog.pg_class.oid
Join pg_catalog.pg_shdepend.refclassid => pg_catalog.pg_class.oid
Join pg_catalog.pg_type.typmodout => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typanalyze => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typbasetype => pg_catalog.pg_type.oid
+Join pg_catalog.pg_type.typcollation => pg_catalog.pg_collation.oid
---------------------------------------------------------------------------
-Bruce Momjian (root@candle.pha.pa.us)
+Bruce Momjian (bruce@momjian.us)
Updated for 7.3 by Joe Conway (mail@joeconway.com)
}
{
printf "\
-SELECT ctid, %s \n\
-FROM %s.%s fk \n\
-WHERE %s != 0 AND \n\
+SELECT ctid, %s\n\
+FROM %s.%s fk\n\
+WHERE %s != 0 AND\n\
NOT EXISTS(SELECT 1 FROM %s.%s pk WHERE pk.oid = fk.%s);\n",
$4, $2, $3, $4,
$6, $7, $4;