5 # You first run findoidjoins on the template1 database, and send that
6 # output into this script to generate a list of SQL statements.
8 # NOTE: any field that findoidjoins thinks joins to more than one table
9 # will NOT be checked by the output of this script. You should be
10 # suspicious of multiple entries in findoidjoins' output.
12 # Caution: you may need to use GNU awk.
15 TMP
="${TMPDIR:-/tmp}/make_oidjoins_check.$$"
16 trap "rm -rf $TMP" 0 1 2 3 15
18 # Create a temporary directory with the proper permissions so no one can
19 # intercept our temporary files and cause a security breach.
23 then echo "Can't create temporary directory $TMP." 1>&2
36 # Look for fields with multiple references.
37 cat $INPUTFILE | cut
-d' ' -f2 |
sort |
uniq -d >$DUPSFILE
38 if [ -s $DUPSFILE ] ; then
39 echo "Ignoring these fields that link to multiple tables:" 1>&2
43 # Get the non-multiply-referenced fields.
44 cat $INPUTFILE |
while read LINE
47 grep "^$2\$" $DUPSFILE >/dev
/null
2>&1 ||
echo $LINE
50 # Generate the output.
57 -- This is created by pgsql/src/tools/findoidjoins/make_oidjoins_check\n\
65 NOT EXISTS(SELECT 1 FROM %s.%s pk WHERE pk.oid = fk.%s);\n",