Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c2635e

Browse files
committed
Fix hard-coded relkind constants in assorted other files.
Although it's reasonable to expect that most of these constants willnever change, that does not make it good programming style to hard-codethe value rather than using the RELKIND_FOO macros.I think I've now gotten all the hard-coded references in C code.Unfortunately there's no equally convenient way to parameterizeSQL files ...Discussion:https://postgr.es/m/11145.1488931324@sss.pgh.pa.us
1 parentfcd8d25 commit9c2635e

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
lines changed

‎contrib/oid2name/oid2name.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
#include"postgres_fe.h"
1111

12+
#include"catalog/pg_class.h"
13+
1214
#include"libpq-fe.h"
1315
#include"pg_getopt.h"
1416

@@ -433,20 +435,21 @@ sql_exec_dumpalltables(PGconn *conn, struct options * opts)
433435

434436
snprintf(todo,sizeof(todo),
435437
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s "
436-
"FROM pg_class c "
438+
"FROMpg_catalog.pg_class c "
437439
"LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
438440
"LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),"
439441
"pg_catalog.pg_tablespace t "
440-
"WHERE relkind IN ('r', 'm'%s%s) AND "
442+
"WHERE relkind IN ("CppAsString2(RELKIND_RELATION) ","
443+
CppAsString2(RELKIND_MATVIEW)"%s%s) AND "
441444
"%s"
442445
"t.oid = CASE"
443446
"WHEN reltablespace <> 0 THEN reltablespace"
444447
"ELSE dattablespace"
445448
"END "
446449
"ORDER BY relname",
447450
opts->extended ?addfields :"",
448-
opts->indexes ?", 'i', 'S'" :"",
449-
opts->systables ?", 't'" :"",
451+
opts->indexes ?","CppAsString2(RELKIND_INDEX)","CppAsString2(RELKIND_SEQUENCE) :"",
452+
opts->systables ?","CppAsString2(RELKIND_TOASTVALUE) :"",
450453
opts->systables ?"" :"n.nspname NOT IN ('pg_catalog', 'information_schema') AND n.nspname !~ '^pg_toast' AND");
451454

452455
sql_exec(conn,todo,opts->quiet);
@@ -507,7 +510,11 @@ sql_exec_searchtables(PGconn *conn, struct options * opts)
507510
"LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"
508511
"LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),\n"
509512
"pg_catalog.pg_tablespace t \n"
510-
"WHERE relkind IN ('r', 'm', 'i', 'S', 't') AND \n"
513+
"WHERE relkind IN ("CppAsString2(RELKIND_RELATION) ","
514+
CppAsString2(RELKIND_MATVIEW)","
515+
CppAsString2(RELKIND_INDEX)","
516+
CppAsString2(RELKIND_SEQUENCE)","
517+
CppAsString2(RELKIND_TOASTVALUE)") AND \n"
511518
"t.oid = CASE\n"
512519
"WHEN reltablespace <> 0 THEN reltablespace\n"
513520
"ELSE dattablespace\n"

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include"access/htup_details.h"
1818
#include"access/sysattr.h"
19+
#include"catalog/pg_class.h"
1920
#include"commands/defrem.h"
2021
#include"commands/explain.h"
2122
#include"commands/vacuum.h"
@@ -3885,7 +3886,11 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
38853886
" adrelid = c.oid AND adnum = attnum ");
38863887

38873888
appendStringInfoString(&buf,
3888-
"WHERE c.relkind IN ('r', 'v', 'f', 'm') "
3889+
"WHERE c.relkind IN ("
3890+
CppAsString2(RELKIND_RELATION)","
3891+
CppAsString2(RELKIND_VIEW)","
3892+
CppAsString2(RELKIND_FOREIGN_TABLE)","
3893+
CppAsString2(RELKIND_MATVIEW)") "
38893894
" AND n.nspname = ");
38903895
deparseStringLiteral(&buf,stmt->remote_schema);
38913896

‎contrib/vacuumlo/vacuumlo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include<termios.h>
2222
#endif
2323

24+
#include"catalog/pg_class.h"
25+
2426
#include"libpq-fe.h"
2527
#include"pg_getopt.h"
2628

@@ -209,7 +211,7 @@ vacuumlo(const char *database, const struct _param * param)
209211
strcat(buf," AND a.atttypid = t.oid ");
210212
strcat(buf," AND c.relnamespace = s.oid ");
211213
strcat(buf," AND t.typname in ('oid', 'lo') ");
212-
strcat(buf," AND c.relkind in ('r', 'm')");
214+
strcat(buf," AND c.relkind in ("CppAsString2(RELKIND_RELATION) "," CppAsString2(RELKIND_MATVIEW) ")");
213215
strcat(buf," AND s.nspname !~ '^pg_'");
214216
res=PQexec(conn,buf);
215217
if (PQresultStatus(res)!=PGRES_TUPLES_OK)

‎src/backend/utils/adt/xml.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
#include"access/htup_details.h"
7171
#include"catalog/namespace.h"
72+
#include"catalog/pg_class.h"
7273
#include"catalog/pg_type.h"
7374
#include"commands/dbcommands.h"
7475
#include"executor/executor.h"
@@ -2344,7 +2345,13 @@ schema_get_xml_visible_tables(Oid nspid)
23442345
StringInfoDataquery;
23452346

23462347
initStringInfo(&query);
2347-
appendStringInfo(&query,"SELECT oid FROM pg_catalog.pg_class WHERE relnamespace = %u AND relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (oid, 'SELECT') ORDER BY relname;",nspid);
2348+
appendStringInfo(&query,"SELECT oid FROM pg_catalog.pg_class"
2349+
" WHERE relnamespace = %u AND relkind IN ("
2350+
CppAsString2(RELKIND_RELATION)","
2351+
CppAsString2(RELKIND_MATVIEW)","
2352+
CppAsString2(RELKIND_VIEW)")"
2353+
" AND pg_catalog.has_table_privilege (oid, 'SELECT')"
2354+
" ORDER BY relname;",nspid);
23482355

23492356
returnquery_to_oid_list(query.data);
23502357
}
@@ -2370,7 +2377,13 @@ static List *
23702377
database_get_xml_visible_tables(void)
23712378
{
23722379
/* At the moment there is no order required here. */
2373-
returnquery_to_oid_list("SELECT oid FROM pg_catalog.pg_class WHERE relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (pg_class.oid, 'SELECT') AND relnamespace IN ("XML_VISIBLE_SCHEMAS");");
2380+
returnquery_to_oid_list("SELECT oid FROM pg_catalog.pg_class"
2381+
" WHERE relkind IN ("
2382+
CppAsString2(RELKIND_RELATION)","
2383+
CppAsString2(RELKIND_MATVIEW)","
2384+
CppAsString2(RELKIND_VIEW)")"
2385+
" AND pg_catalog.has_table_privilege(pg_class.oid, 'SELECT')"
2386+
" AND relnamespace IN ("XML_VISIBLE_SCHEMAS");");
23742387
}
23752388

23762389

‎src/tools/findoidjoins/findoidjoins.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
#include"postgres_fe.h"
99

10+
#include"catalog/pg_class.h"
11+
1012
#include"libpq-fe.h"
1113
#include"pqexpbuffer.h"
1214

@@ -51,8 +53,8 @@ main(int argc, char **argv)
5153
"SELECT c.relname, (SELECT nspname FROM "
5254
"pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname "
5355
"FROM pg_catalog.pg_class c "
54-
"WHERE c.relkind ='r' "
55-
"AND c.relhasoids "
56+
"WHERE c.relkind ="CppAsString2(RELKIND_RELATION)
57+
"AND c.relhasoids "
5658
"ORDER BY nspname, c.relname"
5759
);
5860

@@ -71,9 +73,10 @@ main(int argc, char **argv)
7173
"(SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname, "
7274
"a.attname "
7375
"FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
74-
"WHERE a.attnum > 0 AND c.relkind = 'r' "
75-
"AND a.attrelid = c.oid "
76-
"AND a.atttypid IN ('pg_catalog.oid'::regtype, "
76+
"WHERE a.attnum > 0"
77+
" AND c.relkind = "CppAsString2(RELKIND_RELATION)
78+
" AND a.attrelid = c.oid"
79+
" AND a.atttypid IN ('pg_catalog.oid'::regtype, "
7780
" 'pg_catalog.regclass'::regtype, "
7881
" 'pg_catalog.regoper'::regtype, "
7982
" 'pg_catalog.regoperator'::regtype, "
@@ -146,9 +149,10 @@ main(int argc, char **argv)
146149
"(SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname, "
147150
"a.attname "
148151
"FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
149-
"WHERE a.attnum > 0 AND c.relkind = 'r' "
150-
"AND a.attrelid = c.oid "
151-
"AND a.atttypid IN ('pg_catalog.oid[]'::regtype, "
152+
"WHERE a.attnum > 0"
153+
" AND c.relkind = "CppAsString2(RELKIND_RELATION)
154+
" AND a.attrelid = c.oid"
155+
" AND a.atttypid IN ('pg_catalog.oid[]'::regtype, "
152156
" 'pg_catalog.regclass[]'::regtype, "
153157
" 'pg_catalog.regoper[]'::regtype, "
154158
" 'pg_catalog.regoperator[]'::regtype, "

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp