2 * findoidjoins.c, required pgsql/contrib/pginterface
10 #include "pginterface.h"
16 main(int argc, char **argv)
26 halt("Usage: %s database\n", argv[0]);
28 connectdb(argv[1], NULL, NULL, NULL, NULL);
32 doquery("BEGIN WORK");
34 DECLARE c_attributes BINARY CURSOR FOR \
35 SELECT typname, relname, a.attname \
36 FROM pg_class c, pg_attribute a, pg_type t \
37 WHERE a.attnum > 0 AND \
39 relhasrules = 'f' AND \
41 typname = 'regproc') AND \
42 a.attrelid = c.oid AND \
44 ORDER BY 2, a.attnum ; \
46 doquery("FETCH ALL IN c_attributes");
47 attres = get_result();
50 DECLARE c_relations BINARY CURSOR FOR \
53 WHERE relkind = 'r' AND \
57 doquery("FETCH ALL IN c_relations");
58 relres = get_result();
61 while (fetch(typname, relname, attname) != END_OF_TUPLES)
65 while (fetch(relname2) != END_OF_TUPLES)
68 if (strcmp(typname, "oid") == 0)
70 DECLARE c_matches BINARY CURSOR FOR \
73 WHERE t1.% s = t2.oid ", relname, relname2, attname);
76 DECLARE c_matches BINARY CURSOR FOR \
79 WHERE RegprocToOid(t1.% s) = t2.oid ", relname, relname2, attname);
82 doquery("FETCH ALL IN c_matches");
85 printf("Join %s.%s => %s.oid\n", relname, attname, relname2);
86 doquery("CLOSE c_matches");
93 doquery("CLOSE c_relations");
97 doquery("CLOSE c_attributes");
101 doquery("COMMIT WORK");