]> granicus.if.org Git - postgresql/commitdiff
Fix hard-coded relkind constants in pg_dump.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Mar 2017 00:18:57 +0000 (19:18 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Mar 2017 00:19:25 +0000 (19:19 -0500)
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

index c7876fedd2b42ff2175b741a10a4e3cadc6c5a14..073654e94b5f2096ebd4739deae400915ef93736 100644 (file)
@@ -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;