Skip to content

Commit fe797b4

Browse files
committed
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
1 parent 9cfc4de commit fe797b4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,13 +2208,14 @@ buildMatViewRefreshDependencies(Archive *fout)
22082208
"SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
22092209
"FROM pg_depend d1 "
22102210
"JOIN pg_class c1 ON c1.oid = d1.objid "
2211-
"AND c1.relkind = 'm' "
2212-
"JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2211+
"AND c1.relkind = " CppAsString2(RELKIND_MATVIEW)
2212+
" JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
22132213
"JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
22142214
"AND d2.objid = r1.oid "
22152215
"AND d2.refobjid <> d1.objid "
22162216
"JOIN pg_class c2 ON c2.oid = d2.refobjid "
2217-
"AND c2.relkind IN ('m','v') "
2217+
"AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2218+
CppAsString2(RELKIND_VIEW) ") "
22182219
"WHERE d1.classid = 'pg_class'::regclass "
22192220
"UNION "
22202221
"SELECT w.objid, d3.refobjid, c3.relkind "
@@ -2224,11 +2225,12 @@ buildMatViewRefreshDependencies(Archive *fout)
22242225
"AND d3.objid = r3.oid "
22252226
"AND d3.refobjid <> w.refobjid "
22262227
"JOIN pg_class c3 ON c3.oid = d3.refobjid "
2227-
"AND c3.relkind IN ('m','v') "
2228+
"AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2229+
CppAsString2(RELKIND_VIEW) ") "
22282230
") "
22292231
"SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
22302232
"FROM w "
2231-
"WHERE refrelkind = 'm'");
2233+
"WHERE refrelkind = " CppAsString2(RELKIND_MATVIEW));
22322234

22332235
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
22342236

@@ -5466,7 +5468,8 @@ getTables(Archive *fout, int *numTables)
54665468

54675469
buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
54685470
initracl_subquery, "c.relacl", "c.relowner",
5469-
"CASE WHEN c.relkind = 'S' THEN 's' ELSE 'r' END::\"char\"",
5471+
"CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
5472+
" THEN 's' ELSE 'r' END::\"char\"",
54705473
dopt->binary_upgrade);
54715474

54725475
buildACLQueries(attacl_subquery, attracl_subquery, attinitacl_subquery,
@@ -6174,7 +6177,8 @@ getInherits(Archive *fout, int *numInherits)
61746177
appendPQExpBufferStr(query,
61756178
"SELECT inhrelid, inhparent "
61766179
"FROM pg_inherits "
6177-
"WHERE inhparent NOT IN (SELECT oid FROM pg_class WHERE relkind = 'P')");
6180+
"WHERE inhparent NOT IN (SELECT oid FROM pg_class "
6181+
"WHERE relkind = " CppAsString2(RELKIND_PARTITIONED_TABLE) ")");
61786182

61796183
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
61806184

@@ -14835,7 +14839,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1483514839
{
1483614840
switch (tbinfo->relkind)
1483714841
{
14838-
case (RELKIND_FOREIGN_TABLE):
14842+
case RELKIND_FOREIGN_TABLE:
1483914843
{
1484014844
PQExpBuffer query = createPQExpBuffer();
1484114845
PGresult *res;
@@ -14867,7 +14871,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1486714871
destroyPQExpBuffer(query);
1486814872
break;
1486914873
}
14870-
case (RELKIND_MATVIEW):
14874+
case RELKIND_MATVIEW:
1487114875
reltypename = "MATERIALIZED VIEW";
1487214876
srvname = NULL;
1487314877
ftoptions = NULL;

0 commit comments

Comments
 (0)