diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index da40d7ab678cd48644d1660db3adcbd3bf2b8569..8bca635a3bc1c5893377bd3d65a254c0e1a1a746 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -61,6 +61,7 @@ #include "catalog/catalog.h" #include "catalog/pg_authid.h" +#include "catalog/pg_class.h" #include "common/file_utils.h" #include "common/restricted_token.h" #include "common/username.h" @@ -1691,9 +1692,13 @@ setup_privileges(FILE *cmdfd) " SET relacl = (SELECT array_agg(a.acl) FROM " " (SELECT E'=r/\"$POSTGRES_SUPERUSERNAME\"' as acl " " UNION SELECT unnest(pg_catalog.acldefault(" - " CASE WHEN relkind = 'S' THEN 's' ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))" + " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE) " THEN 's' " + " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))" " ) as a) " - " WHERE relkind IN ('r', 'v', 'm', 'S') AND relacl IS NULL;\n\n", + " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_SEQUENCE) ")" + " AND relacl IS NULL;\n\n", "GRANT USAGE ON SCHEMA pg_catalog TO PUBLIC;\n\n", "GRANT CREATE, USAGE ON SCHEMA public TO PUBLIC;\n\n", "REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n", @@ -1709,7 +1714,9 @@ setup_privileges(FILE *cmdfd) " pg_class" " WHERE" " relacl IS NOT NULL" - " AND relkind IN ('r', 'v', 'm', 'S');", + " AND relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_SEQUENCE) ");", "INSERT INTO pg_init_privs " " (objoid, classoid, objsubid, initprivs, privtype)" " SELECT" @@ -1723,7 +1730,9 @@ setup_privileges(FILE *cmdfd) " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)" " WHERE" " pg_attribute.attacl IS NOT NULL" - " AND pg_class.relkind IN ('r', 'v', 'm', 'S');", + " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_SEQUENCE) ");", "INSERT INTO pg_init_privs " " (objoid, classoid, objsubid, initprivs, privtype)" " SELECT" diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c index 708a47f3cb7c29defa8dd438525aad518ac5b700..e555de885721c88af38b4f2dc045ae14f0f0cf5c 100644 --- a/src/bin/pg_dump/pg_dump_sort.c +++ b/src/bin/pg_dump/pg_dump_sort.c @@ -19,6 +19,8 @@ #include "pg_backup_utils.h" #include "pg_dump.h" +#include "catalog/pg_class.h" + /* translator: this is a module name */ static const char *modulename = gettext_noop("sorter"); @@ -968,8 +970,8 @@ repairDependencyLoop(DumpableObject **loop, if (nLoop == 2 && loop[0]->objType == DO_TABLE && loop[1]->objType == DO_RULE && - (((TableInfo *) loop[0])->relkind == 'v' || /* RELKIND_VIEW */ - ((TableInfo *) loop[0])->relkind == 'm') && /* RELKIND_MATVIEW */ + (((TableInfo *) loop[0])->relkind == RELKIND_VIEW || + ((TableInfo *) loop[0])->relkind == RELKIND_MATVIEW) && ((RuleInfo *) loop[1])->ev_type == '1' && ((RuleInfo *) loop[1])->is_instead && ((RuleInfo *) loop[1])->ruletable == (TableInfo *) loop[0]) @@ -980,8 +982,8 @@ repairDependencyLoop(DumpableObject **loop, if (nLoop == 2 && loop[1]->objType == DO_TABLE && loop[0]->objType == DO_RULE && - (((TableInfo *) loop[1])->relkind == 'v' || /* RELKIND_VIEW */ - ((TableInfo *) loop[1])->relkind == 'm') && /* RELKIND_MATVIEW */ + (((TableInfo *) loop[1])->relkind == RELKIND_VIEW || + ((TableInfo *) loop[1])->relkind == RELKIND_MATVIEW) && ((RuleInfo *) loop[0])->ev_type == '1' && ((RuleInfo *) loop[0])->is_instead && ((RuleInfo *) loop[0])->ruletable == (TableInfo *) loop[1]) @@ -996,7 +998,7 @@ repairDependencyLoop(DumpableObject **loop, for (i = 0; i < nLoop; i++) { if (loop[i]->objType == DO_TABLE && - ((TableInfo *) loop[i])->relkind == 'v') /* RELKIND_VIEW */ + ((TableInfo *) loop[i])->relkind == RELKIND_VIEW) { for (j = 0; j < nLoop; j++) { @@ -1019,7 +1021,7 @@ repairDependencyLoop(DumpableObject **loop, for (i = 0; i < nLoop; i++) { if (loop[i]->objType == DO_TABLE && - ((TableInfo *) loop[i])->relkind == 'm') /* RELKIND_MATVIEW */ + ((TableInfo *) loop[i])->relkind == RELKIND_MATVIEW) { for (j = 0; j < nLoop; j++) { diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c index 853d8990ffa5edfd1506c92cbedd5f265bf5409a..6500302c3d441188a7694b86420c684c0d03baaa 100644 --- a/src/bin/pg_upgrade/info.c +++ b/src/bin/pg_upgrade/info.c @@ -12,6 +12,7 @@ #include "pg_upgrade.h" #include "access/transam.h" +#include "catalog/pg_class.h" static void create_rel_filename_map(const char *old_data, const char *new_data, @@ -444,7 +445,8 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo) " SELECT c.oid, 0::oid, 0::oid " " FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n " " ON c.relnamespace = n.oid " - " WHERE relkind IN ('r', 'm') AND " + " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ") AND " /* exclude possible orphaned temp tables */ " ((n.nspname !~ '^pg_temp_' AND " " n.nspname !~ '^pg_toast_temp_' AND " diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index 145d2da69c4a8c2455f45d0e9494b0f7cbc112a7..fc66d93dd6a7a4314f028a6ae3a777d0e0c44491 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -37,6 +37,7 @@ #include "postgres_fe.h" #include "pg_upgrade.h" +#include "catalog/pg_class.h" #include "common/restricted_token.h" #include "fe_utils/string_utils.h" @@ -565,7 +566,10 @@ set_frozenxids(bool minmxid_only) "UPDATE pg_catalog.pg_class " "SET relfrozenxid = '%u' " /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN ('r', 'm', 't')", + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ @@ -573,7 +577,10 @@ set_frozenxids(bool minmxid_only) "UPDATE pg_catalog.pg_class " "SET relminmxid = '%u' " /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN ('r', 'm', 't')", + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", old_cluster.controldata.chkpnt_nxtmulti)); PQfinish(conn); diff --git a/src/bin/pg_upgrade/version.c b/src/bin/pg_upgrade/version.c index aa462daed3dbef34b9b6f2f0c388e63fa0a181e8..a3651aadede0763caca87c56d10bed985f005d03 100644 --- a/src/bin/pg_upgrade/version.c +++ b/src/bin/pg_upgrade/version.c @@ -10,6 +10,8 @@ #include "postgres_fe.h" #include "pg_upgrade.h" + +#include "catalog/pg_class.h" #include "fe_utils/string_utils.h" @@ -234,7 +236,10 @@ old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster) "WHERE c.oid = a.attrelid AND " " NOT a.attisdropped AND " " a.atttypid = 'pg_catalog.unknown'::pg_catalog.regtype AND " - " c.relkind IN ('r', 'c', 'm') AND " + " c.relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_COMPOSITE_TYPE) ", " + CppAsString2(RELKIND_MATVIEW) ") AND " " c.relnamespace = n.oid AND " /* exclude possible orphaned temp tables */ " n.nspname !~ '^pg_temp_' AND " diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 07efc27a697cd78a9427e2d6a0f240414e676df4..4f4a0aa9bd48e85cc5a6535ee1dc5173cb0096a8 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -27,6 +27,7 @@ #include <sys/stat.h> /* for stat() */ #endif +#include "catalog/pg_class.h" #include "portability/instr_time.h" #include "libpq-fe.h" @@ -3465,11 +3466,11 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, switch (relkind[0]) { #ifdef NOT_USED - case 'm': + case RELKIND_MATVIEW: appendPQExpBufferStr(buf, "CREATE OR REPLACE MATERIALIZED VIEW "); break; #endif - case 'v': + case RELKIND_VIEW: appendPQExpBufferStr(buf, "CREATE OR REPLACE VIEW "); break; default: diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 121a492e6d8517ce1df4dfe4faef79131344e16f..e8458e939ee1de4c8400b52d78591318f1f0d82d 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -40,6 +40,9 @@ #ifdef USE_READLINE #include <ctype.h> + +#include "catalog/pg_class.h" + #include "libpq-fe.h" #include "pqexpbuffer.h" #include "common.h" @@ -85,8 +88,9 @@ typedef struct SchemaQuery /* * Selection condition --- only rows meeting this condition are candidates * to display. If catname mentions multiple tables, include the necessary - * join condition here. For example, "c.relkind = 'r'". Write NULL (not - * an empty string) if not needed. + * join condition here. For example, this might look like "c.relkind = " + * CppAsString2(RELKIND_RELATION). Write NULL (not an empty string) if + * not needed. */ const char *selcondition; @@ -361,7 +365,8 @@ static const SchemaQuery Query_for_list_of_datatypes = { "pg_catalog.pg_type t", /* selcondition --- ignore table rowtypes and array types */ "(t.typrelid = 0 " - " OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) " + " OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE) + " FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) " "AND t.typname !~ '^_'", /* viscondition */ "pg_catalog.pg_type_is_visible(t.oid)", @@ -407,7 +412,7 @@ static const SchemaQuery Query_for_list_of_indexes = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('i')", + "c.relkind IN (" CppAsString2(RELKIND_INDEX) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -422,7 +427,7 @@ static const SchemaQuery Query_for_list_of_sequences = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('S')", + "c.relkind IN (" CppAsString2(RELKIND_SEQUENCE) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -437,7 +442,7 @@ static const SchemaQuery Query_for_list_of_foreign_tables = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('f')", + "c.relkind IN (" CppAsString2(RELKIND_FOREIGN_TABLE) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -452,7 +457,8 @@ static const SchemaQuery Query_for_list_of_tables = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('r', 'P')", + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_PARTITIONED_TABLE) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -467,7 +473,7 @@ static const SchemaQuery Query_for_list_of_partitioned_tables = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('P')", + "c.relkind IN (" CppAsString2(RELKIND_PARTITIONED_TABLE) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -498,7 +504,10 @@ static const SchemaQuery Query_for_list_of_updatables = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('r', 'f', 'v', 'P')", + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_FOREIGN_TABLE) ", " + CppAsString2(RELKIND_VIEW) ", " + CppAsString2(RELKIND_PARTITIONED_TABLE) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -528,7 +537,12 @@ static const SchemaQuery Query_for_list_of_tsvmf = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('r', 'S', 'v', 'm', 'f', 'P')", + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_SEQUENCE) ", " + CppAsString2(RELKIND_VIEW) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_FOREIGN_TABLE) ", " + CppAsString2(RELKIND_PARTITIONED_TABLE) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -543,7 +557,9 @@ static const SchemaQuery Query_for_list_of_tmf = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('r', 'm', 'f')", + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_FOREIGN_TABLE) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -558,7 +574,8 @@ static const SchemaQuery Query_for_list_of_tm = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('r', 'm')", + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -573,7 +590,7 @@ static const SchemaQuery Query_for_list_of_views = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('v')", + "c.relkind IN (" CppAsString2(RELKIND_VIEW) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ @@ -588,7 +605,7 @@ static const SchemaQuery Query_for_list_of_matviews = { /* catname */ "pg_catalog.pg_class c", /* selcondition */ - "c.relkind IN ('m')", + "c.relkind IN (" CppAsString2(RELKIND_MATVIEW) ")", /* viscondition */ "pg_catalog.pg_table_is_visible(c.oid)", /* namespace */ diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index d3fa51cf1fa06801129ccfb30eca009931fc3903..e2b187eab3ac3193fc37513edad4324c4cef9971 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -16,6 +16,8 @@ #include <sys/select.h> #endif +#include "catalog/pg_class.h" + #include "common.h" #include "fe_utils/simple_list.h" #include "fe_utils/string_utils.h" @@ -388,8 +390,12 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts, initPQExpBuffer(&buf); res = executeQuery(conn, - "SELECT c.relname, ns.nspname FROM pg_class c, pg_namespace ns\n" - " WHERE relkind IN (\'r\', \'m\') AND c.relnamespace = ns.oid\n" + "SELECT c.relname, ns.nspname" + " FROM pg_class c, pg_namespace ns\n" + " WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ")" + " AND c.relnamespace = ns.oid\n" " ORDER BY c.relpages DESC;", progname, echo);