postgresql/contrib/findoidjoins/make_oidjoins_check
Tom Lane bf56f0759b Make OIDs optional, per discussions in pghackers. WITH OIDS is still the
default, but OIDS are removed from many system catalogs that don't need them.
Some interesting side effects: TOAST pointers are 20 bytes not 32 now;
pg_description has a three-column key instead of one.

Bugs fixed in passing: BINARY cursors work again; pg_class.relhaspkey
has some usefulness; pg_dump dumps comments on indexes, rules, and
triggers in a valid order.

initdb forced.
2001-08-10 18:57:42 +00:00

54 lines
1.2 KiB
Bash
Executable File

#! /bin/sh
# You first run findoidjoins on the template1 database, and send that
# output into this script to generate a list of SQL statements.
# NOTE: any field that findoidjoins thinks joins to more than one table
# will NOT be checked by the output of this script. You should be
# suspicious of multiple entries in findoidjoins' output.
# Caution: you may need to use GNU awk.
AWK=${AWK:-awk}
trap "rm -f /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
# Read input
cat "$@" >/tmp/$$
# Look for fields with multiple references.
cat /tmp/$$ | cut -d' ' -f2 | sort | uniq -d >/tmp/$$a
if [ -s /tmp/$$a ] ; then
echo "Ignoring these fields that link to multiple tables:" 1>&2
cat /tmp/$$a 1>&2
fi
# Get the non-multiply-referenced fields.
cat /tmp/$$ | while read LINE
do
set -- $LINE
grep "$2" /tmp/$$a >/dev/null 2>&1 || echo $LINE
done >/tmp/$$b
# Generate the output.
cat /tmp/$$b |
$AWK -F'[ \.]' '\
BEGIN \
{
printf "\
--\n\
-- This is created by pgsql/contrib/findoidjoins/make_oidjoin_check\n\
--\n";
}
{
printf "\
SELECT ctid, %s.%s \n\
FROM %s \n\
WHERE %s.%s != 0 AND \n\
NOT EXISTS(SELECT * FROM %s AS t1 WHERE t1.oid = %s.%s);\n",
$2, $3, $2,
$2, $3,
$5, $2, $3;
}'
exit 0