query = createPQExpBuffer();
- appendPQExpBufferStr(query, "with recursive w as "
+ appendPQExpBufferStr(query, "WITH RECURSIVE w AS "
"( "
- "select d1.objid, d2.refobjid, c2.relkind as refrelkind "
- "from pg_depend d1 "
- "join pg_class c1 on c1.oid = d1.objid "
- "and c1.relkind = 'm' "
- "join pg_rewrite r1 on r1.ev_class = d1.objid "
- "join pg_depend d2 on d2.classid = 'pg_rewrite'::regclass "
- "and d2.objid = r1.oid "
- "and d2.refobjid <> d1.objid "
- "join pg_class c2 on c2.oid = d2.refobjid "
- "and c2.relkind in ('m','v') "
- "where d1.classid = 'pg_class'::regclass "
- "union "
- "select w.objid, d3.refobjid, c3.relkind "
- "from w "
- "join pg_rewrite r3 on r3.ev_class = w.refobjid "
- "join pg_depend d3 on d3.classid = 'pg_rewrite'::regclass "
- "and d3.objid = r3.oid "
- "and d3.refobjid <> w.refobjid "
- "join pg_class c3 on c3.oid = d3.refobjid "
- "and c3.relkind in ('m','v') "
+ "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
+ "FROM pg_depend d1 "
+ "JOIN pg_class c1 ON c1.oid = d1.objid "
+ "AND c1.relkind = 'm' "
+ "JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
+ "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
+ "AND d2.objid = r1.oid "
+ "AND d2.refobjid <> d1.objid "
+ "JOIN pg_class c2 ON c2.oid = d2.refobjid "
+ "AND c2.relkind IN ('m','v') "
+ "WHERE d1.classid = 'pg_class'::regclass "
+ "UNION "
+ "SELECT w.objid, d3.refobjid, c3.relkind "
+ "FROM w "
+ "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
+ "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
+ "AND d3.objid = r3.oid "
+ "AND d3.refobjid <> w.refobjid "
+ "JOIN pg_class c3 ON c3.oid = d3.refobjid "
+ "AND c3.relkind IN ('m','v') "
") "
- "select 'pg_class'::regclass::oid as classid, objid, refobjid "
- "from w "
- "where refrelkind = 'm'");
+ "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
+ "FROM w "
+ "WHERE refrelkind = 'm'");
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);