From fe797b4a6a69ec0c9bf6ff992eac20c4084fda41 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 9 Mar 2017 19:18:57 -0500 Subject: [PATCH] Fix hard-coded relkind constants in pg_dump.c. Although it's reasonable to expect that most of these constants will never change, that does not make it good programming style to hard-code the value rather than using the RELKIND_FOO macros. There were only a few such violations, and all relatively new AFAICT. Existing style is mostly to inject relkind values into constructed query strings using %c. I did not bother to touch places that did it like that, but really a better technique is to stringify the RELKIND macro, at least in places where you'd want single quotes around the code character. That avoids any runtime effort and keeps the RELKIND symbol close to where it's used. Discussion: https://postgr.es/m/11145.1488931324@sss.pgh.pa.us --- src/bin/pg_dump/pg_dump.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index c7876fedd2..073654e94b 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -2208,13 +2208,14 @@ buildMatViewRefreshDependencies(Archive *fout) "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 " + "AND c1.relkind = " CppAsString2(RELKIND_MATVIEW) + " 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') " + "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW) "," + CppAsString2(RELKIND_VIEW) ") " "WHERE d1.classid = 'pg_class'::regclass " "UNION " "SELECT w.objid, d3.refobjid, c3.relkind " @@ -2224,11 +2225,12 @@ buildMatViewRefreshDependencies(Archive *fout) "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') " + "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW) "," + CppAsString2(RELKIND_VIEW) ") " ") " "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid " "FROM w " - "WHERE refrelkind = 'm'"); + "WHERE refrelkind = " CppAsString2(RELKIND_MATVIEW)); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -5466,7 +5468,8 @@ getTables(Archive *fout, int *numTables) buildACLQueries(acl_subquery, racl_subquery, initacl_subquery, initracl_subquery, "c.relacl", "c.relowner", - "CASE WHEN c.relkind = 'S' THEN 's' ELSE 'r' END::\"char\"", + "CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE) + " THEN 's' ELSE 'r' END::\"char\"", dopt->binary_upgrade); buildACLQueries(attacl_subquery, attracl_subquery, attinitacl_subquery, @@ -6174,7 +6177,8 @@ getInherits(Archive *fout, int *numInherits) appendPQExpBufferStr(query, "SELECT inhrelid, inhparent " "FROM pg_inherits " - "WHERE inhparent NOT IN (SELECT oid FROM pg_class WHERE relkind = 'P')"); + "WHERE inhparent NOT IN (SELECT oid FROM pg_class " + "WHERE relkind = " CppAsString2(RELKIND_PARTITIONED_TABLE) ")"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -14835,7 +14839,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) { switch (tbinfo->relkind) { - case (RELKIND_FOREIGN_TABLE): + case RELKIND_FOREIGN_TABLE: { PQExpBuffer query = createPQExpBuffer(); PGresult *res; @@ -14867,7 +14871,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) destroyPQExpBuffer(query); break; } - case (RELKIND_MATVIEW): + case RELKIND_MATVIEW: reltypename = "MATERIALIZED VIEW"; srvname = NULL; ftoptions = NULL; -- 2.40.0