1999-03-26 15:21:58 +08:00
|
|
|
#! /bin/sh
|
|
|
|
|
1998-09-14 09:14:49 +08:00
|
|
|
# You first run findoidjoins on the template1 database, and send that
|
2001-08-11 02:57:42 +08:00
|
|
|
# output into this script to generate a list of SQL statements.
|
1999-03-26 15:21:58 +08:00
|
|
|
|
|
|
|
# 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}
|
|
|
|
|
1998-09-14 09:14:49 +08:00
|
|
|
trap "rm -f /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
|
|
|
|
|
1999-03-26 15:21:58 +08:00
|
|
|
# Read input
|
1998-09-14 09:14:49 +08:00
|
|
|
cat "$@" >/tmp/$$
|
1999-03-26 15:21:58 +08:00
|
|
|
|
|
|
|
# Look for fields with multiple references.
|
1998-09-14 09:14:49 +08:00
|
|
|
cat /tmp/$$ | cut -d' ' -f2 | sort | uniq -d >/tmp/$$a
|
1999-03-26 15:21:58 +08:00
|
|
|
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.
|
1998-09-14 09:14:49 +08:00
|
|
|
cat /tmp/$$ | while read LINE
|
|
|
|
do
|
|
|
|
set -- $LINE
|
|
|
|
grep "$2" /tmp/$$a >/dev/null 2>&1 || echo $LINE
|
|
|
|
done >/tmp/$$b
|
1999-03-26 15:21:58 +08:00
|
|
|
|
|
|
|
# Generate the output.
|
1998-09-14 09:14:49 +08:00
|
|
|
cat /tmp/$$b |
|
1999-03-26 15:21:58 +08:00
|
|
|
$AWK -F'[ \.]' '\
|
1998-09-14 09:14:49 +08:00
|
|
|
BEGIN \
|
|
|
|
{
|
|
|
|
printf "\
|
|
|
|
--\n\
|
|
|
|
-- This is created by pgsql/contrib/findoidjoins/make_oidjoin_check\n\
|
|
|
|
--\n";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
printf "\
|
2001-08-11 02:57:42 +08:00
|
|
|
SELECT ctid, %s.%s \n\
|
1998-09-14 09:14:49 +08:00
|
|
|
FROM %s \n\
|
1999-03-26 15:21:58 +08:00
|
|
|
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;
|
1998-09-14 09:14:49 +08:00
|
|
|
}'
|
1999-03-26 15:21:58 +08:00
|
|
|
|
|
|
|
exit 0
|