diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 48 | ||||
-rw-r--r-- | src/bin/pg_dump/dumputils.c | 100 | ||||
-rw-r--r-- | src/bin/pg_dump/dumputils.h | 6 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_backup.h | 3 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 53 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.h | 4 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 1752 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dumpall.c | 34 | ||||
-rw-r--r-- | src/bin/pg_dump/t/002_pg_dump.pl | 384 | ||||
-rw-r--r-- | src/test/modules/test_pg_dump/t/001_base.pl | 50 | ||||
-rw-r--r-- | src/test/regress/expected/collate.icu.utf8.out | 12 | ||||
-rw-r--r-- | src/test/regress/expected/collate.linux.utf8.out | 12 | ||||
-rw-r--r-- | src/test/regress/expected/collate.out | 12 | ||||
-rw-r--r-- | src/test/regress/expected/indexing.out | 98 | ||||
-rw-r--r-- | src/test/regress/expected/rules.out | 78 | ||||
-rw-r--r-- | src/test/regress/expected/triggers.out | 12 |
16 files changed, 1166 insertions, 1492 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index ba9fab4582f..36974667892 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -86,15 +86,17 @@ #define PRETTYINDENT_LIMIT 40 /* wrap limit */ /* Pretty flags */ -#define PRETTYFLAG_PAREN 1 -#define PRETTYFLAG_INDENT 2 +#define PRETTYFLAG_PAREN 0x0001 +#define PRETTYFLAG_INDENT 0x0002 +#define PRETTYFLAG_SCHEMA 0x0004 /* Default line length for pretty-print wrapping: 0 means wrap always */ #define WRAP_COLUMN_DEFAULT 0 -/* macro to test if pretty action needed */ +/* macros to test if pretty action needed */ #define PRETTY_PAREN(context) ((context)->prettyFlags & PRETTYFLAG_PAREN) #define PRETTY_INDENT(context) ((context)->prettyFlags & PRETTYFLAG_INDENT) +#define PRETTY_SCHEMA(context) ((context)->prettyFlags & PRETTYFLAG_SCHEMA) /* ---------- @@ -499,7 +501,7 @@ pg_get_ruledef_ext(PG_FUNCTION_ARGS) int prettyFlags; char *res; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; res = pg_get_ruledef_worker(ruleoid, prettyFlags); @@ -620,7 +622,7 @@ pg_get_viewdef_ext(PG_FUNCTION_ARGS) int prettyFlags; char *res; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT); @@ -640,7 +642,7 @@ pg_get_viewdef_wrap(PG_FUNCTION_ARGS) char *res; /* calling this implies we want pretty printing */ - prettyFlags = PRETTYFLAG_PAREN | PRETTYFLAG_INDENT; + prettyFlags = PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA; res = pg_get_viewdef_worker(viewoid, prettyFlags, wrap); @@ -686,7 +688,7 @@ pg_get_viewdef_name_ext(PG_FUNCTION_ARGS) Oid viewoid; char *res; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; /* Look up view name. Can't lock it - we might not have privileges. */ viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname)); @@ -922,8 +924,15 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) appendStringInfoString(&buf, " TRUNCATE"); findx++; } + + /* + * In non-pretty mode, always schema-qualify the target table name for + * safety. In pretty mode, schema-qualify only if not visible. + */ appendStringInfo(&buf, " ON %s ", - generate_relation_name(trigrec->tgrelid, NIL)); + pretty ? + generate_relation_name(trigrec->tgrelid, NIL) : + generate_qualified_relation_name(trigrec->tgrelid)); if (OidIsValid(trigrec->tgconstraint)) { @@ -1017,7 +1026,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) context.windowClause = NIL; context.windowTList = NIL; context.varprefix = true; - context.prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + context.prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; context.wrapColumn = WRAP_COLUMN_DEFAULT; context.indentLevel = PRETTYINDENT_STD; context.special_exprkind = EXPR_KIND_NONE; @@ -1104,7 +1113,7 @@ pg_get_indexdef_ext(PG_FUNCTION_ARGS) int prettyFlags; char *res; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; res = pg_get_indexdef_worker(indexrelid, colno, NULL, colno != 0, false, false, prettyFlags, true); @@ -1132,7 +1141,8 @@ pg_get_indexdef_columns(Oid indexrelid, bool pretty) { int prettyFlags; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; + return pg_get_indexdef_worker(indexrelid, 0, NULL, true, false, false, prettyFlags, false); } @@ -1264,7 +1274,9 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, quote_identifier(NameStr(idxrelrec->relname)), idxrelrec->relkind == RELKIND_PARTITIONED_INDEX && !inherits ? "ONLY " : "", - generate_relation_name(indrelid, NIL), + (prettyFlags & PRETTYFLAG_SCHEMA) ? + generate_relation_name(indrelid, NIL) : + generate_qualified_relation_name(indrelid), quote_identifier(NameStr(amrec->amname))); else /* currently, must be EXCLUDE constraint */ appendStringInfo(&buf, "EXCLUDE USING %s (", @@ -1575,7 +1587,8 @@ pg_get_partkeydef_columns(Oid relid, bool pretty) { int prettyFlags; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; + return pg_get_partkeydef_worker(relid, prettyFlags, true, false); } @@ -1803,7 +1816,7 @@ pg_get_constraintdef_ext(PG_FUNCTION_ARGS) int prettyFlags; char *res; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; res = pg_get_constraintdef_worker(constraintId, false, prettyFlags, true); @@ -2258,7 +2271,7 @@ pg_get_expr_ext(PG_FUNCTION_ARGS) int prettyFlags; char *relname; - prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + prettyFlags = pretty ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) : PRETTYFLAG_INDENT; if (OidIsValid(relid)) { @@ -4709,7 +4722,10 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, } /* The relation the rule is fired on */ - appendStringInfo(buf, " TO %s", generate_relation_name(ev_class, NIL)); + appendStringInfo(buf, " TO %s", + (prettyFlags & PRETTYFLAG_SCHEMA) ? + generate_relation_name(ev_class, NIL) : + generate_qualified_relation_name(ev_class)); /* If the rule has an event qualification, add it */ if (ev_qual == NULL) diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index 7afddc31533..7f5bb1343e0 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -32,6 +32,7 @@ static void AddAcl(PQExpBuffer aclbuf, const char *keyword, * * name: the object name, in the form to use in the commands (already quoted) * subname: the sub-object name, if any (already quoted); NULL if none + * nspname: the namespace the object is in (NULL if none); not pre-quoted * type: the object type (as seen in GRANT command: must be one of * TABLE, SEQUENCE, FUNCTION, PROCEDURE, LANGUAGE, SCHEMA, DATABASE, TABLESPACE, * FOREIGN DATA WRAPPER, SERVER, or LARGE OBJECT) @@ -52,7 +53,7 @@ static void AddAcl(PQExpBuffer aclbuf, const char *keyword, * since this routine uses fmtId() internally. */ bool -buildACLCommands(const char *name, const char *subname, +buildACLCommands(const char *name, const char *subname, const char *nspname, const char *type, const char *acls, const char *racls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql) @@ -152,7 +153,10 @@ buildACLCommands(const char *name, const char *subname, appendPQExpBuffer(firstsql, "%sREVOKE ALL", prefix); if (subname) appendPQExpBuffer(firstsql, "(%s)", subname); - appendPQExpBuffer(firstsql, " ON %s %s FROM PUBLIC;\n", type, name); + appendPQExpBuffer(firstsql, " ON %s ", type); + if (nspname && *nspname) + appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(firstsql, "%s FROM PUBLIC;\n", name); } else { @@ -170,8 +174,11 @@ buildACLCommands(const char *name, const char *subname, { if (privs->len > 0) { - appendPQExpBuffer(firstsql, "%sREVOKE %s ON %s %s FROM ", - prefix, privs->data, type, name); + appendPQExpBuffer(firstsql, "%sREVOKE %s ON %s ", + prefix, privs->data, type); + if (nspname && *nspname) + appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(firstsql, "%s FROM ", name); if (grantee->len == 0) appendPQExpBufferStr(firstsql, "PUBLIC;\n"); else if (strncmp(grantee->data, "group ", @@ -185,8 +192,11 @@ buildACLCommands(const char *name, const char *subname, if (privswgo->len > 0) { appendPQExpBuffer(firstsql, - "%sREVOKE GRANT OPTION FOR %s ON %s %s FROM ", - prefix, privswgo->data, type, name); + "%sREVOKE GRANT OPTION FOR %s ON %s ", + prefix, privswgo->data, type); + if (nspname && *nspname) + appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(firstsql, "%s FROM ", name); if (grantee->len == 0) appendPQExpBufferStr(firstsql, "PUBLIC"); else if (strncmp(grantee->data, "group ", @@ -251,18 +261,33 @@ buildACLCommands(const char *name, const char *subname, appendPQExpBuffer(firstsql, "%sREVOKE ALL", prefix); if (subname) appendPQExpBuffer(firstsql, "(%s)", subname); - appendPQExpBuffer(firstsql, " ON %s %s FROM %s;\n", - type, name, fmtId(grantee->data)); + appendPQExpBuffer(firstsql, " ON %s ", type); + if (nspname && *nspname) + appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(firstsql, "%s FROM %s;\n", + name, fmtId(grantee->data)); if (privs->len > 0) + { appendPQExpBuffer(firstsql, - "%sGRANT %s ON %s %s TO %s;\n", - prefix, privs->data, type, name, - fmtId(grantee->data)); + "%sGRANT %s ON %s ", + prefix, privs->data, type); + if (nspname && *nspname) + appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(firstsql, + "%s TO %s;\n", + name, fmtId(grantee->data)); + } if (privswgo->len > 0) + { appendPQExpBuffer(firstsql, - "%sGRANT %s ON %s %s TO %s WITH GRANT OPTION;\n", - prefix, privswgo->data, type, name, - fmtId(grantee->data)); + "%sGRANT %s ON %s ", + prefix, privswgo->data, type); + if (nspname && *nspname) + appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(firstsql, + "%s TO %s WITH GRANT OPTION;\n", + name, fmtId(grantee->data)); + } } } else @@ -284,8 +309,11 @@ buildACLCommands(const char *name, const char *subname, if (privs->len > 0) { - appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ", - prefix, privs->data, type, name); + appendPQExpBuffer(secondsql, "%sGRANT %s ON %s ", + prefix, privs->data, type); + if (nspname && *nspname) + appendPQExpBuffer(secondsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(secondsql, "%s TO ", name); if (grantee->len == 0) appendPQExpBufferStr(secondsql, "PUBLIC;\n"); else if (strncmp(grantee->data, "group ", @@ -297,8 +325,11 @@ buildACLCommands(const char *name, const char *subname, } if (privswgo->len > 0) { - appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ", - prefix, privswgo->data, type, name); + appendPQExpBuffer(secondsql, "%sGRANT %s ON %s ", + prefix, privswgo->data, type); + if (nspname && *nspname) + appendPQExpBuffer(secondsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(secondsql, "%s TO ", name); if (grantee->len == 0) appendPQExpBufferStr(secondsql, "PUBLIC"); else if (strncmp(grantee->data, "group ", @@ -328,8 +359,11 @@ buildACLCommands(const char *name, const char *subname, appendPQExpBuffer(firstsql, "%sREVOKE ALL", prefix); if (subname) appendPQExpBuffer(firstsql, "(%s)", subname); - appendPQExpBuffer(firstsql, " ON %s %s FROM %s;\n", - type, name, fmtId(owner)); + appendPQExpBuffer(firstsql, " ON %s ", type); + if (nspname && *nspname) + appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); + appendPQExpBuffer(firstsql, "%s FROM %s;\n", + name, fmtId(owner)); } destroyPQExpBuffer(grantee); @@ -388,7 +422,8 @@ buildDefaultACLCommands(const char *type, const char *nspname, if (strlen(initacls) != 0 || strlen(initracls) != 0) { appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n"); - if (!buildACLCommands("", NULL, type, initacls, initracls, owner, + if (!buildACLCommands("", NULL, NULL, type, + initacls, initracls, owner, prefix->data, remoteVersion, sql)) { destroyPQExpBuffer(prefix); @@ -397,7 +432,8 @@ buildDefaultACLCommands(const char *type, const char *nspname, appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n"); } - if (!buildACLCommands("", NULL, type, acls, racls, owner, + if (!buildACLCommands("", NULL, NULL, type, + acls, racls, owner, prefix->data, remoteVersion, sql)) { destroyPQExpBuffer(prefix); @@ -641,26 +677,32 @@ AddAcl(PQExpBuffer aclbuf, const char *keyword, const char *subname) * buildShSecLabelQuery * * Build a query to retrieve security labels for a shared object. + * The object is identified by its OID plus the name of the catalog + * it can be found in (e.g., "pg_database" for database names). + * The query is appended to "sql". (We don't execute it here so as to + * keep this file free of assumptions about how to deal with SQL errors.) */ void -buildShSecLabelQuery(PGconn *conn, const char *catalog_name, uint32 objectId, +buildShSecLabelQuery(PGconn *conn, const char *catalog_name, Oid objectId, PQExpBuffer sql) { appendPQExpBuffer(sql, "SELECT provider, label FROM pg_catalog.pg_shseclabel " - "WHERE classoid = '%s'::pg_catalog.regclass AND " - "objoid = %u", catalog_name, objectId); + "WHERE classoid = 'pg_catalog.%s'::pg_catalog.regclass " + "AND objoid = '%u'", catalog_name, objectId); } /* * emitShSecLabels * - * Format security label data retrieved by the query generated in - * buildShSecLabelQuery. + * Construct SECURITY LABEL commands using the data retrieved by the query + * generated by buildShSecLabelQuery, and append them to "buffer". + * Here, the target object is identified by its type name (e.g. "DATABASE") + * and its name (not pre-quoted). */ void emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, - const char *target, const char *objname) + const char *objtype, const char *objname) { int i; @@ -672,7 +714,7 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, /* must use fmtId result before calling it again */ appendPQExpBuffer(buffer, "SECURITY LABEL FOR %s ON %s", - fmtId(provider), target); + fmtId(provider), objtype); appendPQExpBuffer(buffer, " %s IS ", fmtId(objname)); diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h index 23a0645be8a..a9e26ae72a8 100644 --- a/src/bin/pg_dump/dumputils.h +++ b/src/bin/pg_dump/dumputils.h @@ -36,7 +36,7 @@ #endif -extern bool buildACLCommands(const char *name, const char *subname, +extern bool buildACLCommands(const char *name, const char *subname, const char *nspname, const char *type, const char *acls, const char *racls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql); @@ -47,9 +47,9 @@ extern bool buildDefaultACLCommands(const char *type, const char *nspname, int remoteVersion, PQExpBuffer sql); extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name, - uint32 objectId, PQExpBuffer sql); + Oid objectId, PQExpBuffer sql); extern void emitShSecLabels(PGconn *conn, PGresult *res, - PQExpBuffer buffer, const char *target, const char *objname); + PQExpBuffer buffer, const char *objtype, const char *objname); extern void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery, PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery, diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index 520cd095d3e..ceedd481fb4 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -197,6 +197,9 @@ typedef struct Archive /* info needed for string escaping */ int encoding; /* libpq code for client_encoding */ bool std_strings; /* standard_conforming_strings */ + + /* other important stuff */ + char *searchpath; /* search_path to set during restore */ char *use_role; /* Issue SET ROLE to this */ /* error handling */ diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index a4deb53e3a8..fc233a608f3 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -70,6 +70,7 @@ static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName); static void _selectTablespace(ArchiveHandle *AH, const char *tablespace); static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te); static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te); +static void processSearchPathEntry(ArchiveHandle *AH, TocEntry *te); static teReqs _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH); static RestorePass _tocEntryRestorePass(TocEntry *te); static bool _tocEntryIsACL(TocEntry *te); @@ -900,7 +901,9 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel) ahprintf(AH, "TRUNCATE TABLE %s%s;\n\n", (PQserverVersion(AH->connection) >= 80400 ? "ONLY " : ""), - fmtId(te->tag)); + fmtQualifiedId(PQserverVersion(AH->connection), + te->namespace, + te->tag)); } /* @@ -987,10 +990,10 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te) /* * Disable them. */ - _selectOutputSchema(AH, te->namespace); - ahprintf(AH, "ALTER TABLE %s DISABLE TRIGGER ALL;\n\n", - fmtId(te->tag)); + fmtQualifiedId(PQserverVersion(AH->connection), + te->namespace, + te->tag)); } static void @@ -1015,10 +1018,10 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te) /* * Enable them. */ - _selectOutputSchema(AH, te->namespace); - ahprintf(AH, "ALTER TABLE %s ENABLE TRIGGER ALL;\n\n", - fmtId(te->tag)); + fmtQualifiedId(PQserverVersion(AH->connection), + te->namespace, + te->tag)); } /* @@ -2711,6 +2714,8 @@ ReadToc(ArchiveHandle *AH) processEncodingEntry(AH, te); else if (strcmp(te->desc, "STDSTRINGS") == 0) processStdStringsEntry(AH, te); + else if (strcmp(te->desc, "SEARCHPATH") == 0) + processSearchPathEntry(AH, te); } } @@ -2759,6 +2764,16 @@ processStdStringsEntry(ArchiveHandle *AH, TocEntry *te) } static void +processSearchPathEntry(ArchiveHandle *AH, TocEntry *te) +{ + /* + * te->defn should contain a command to set search_path. We just copy it + * verbatim for use later. + */ + AH->public.searchpath = pg_strdup(te->defn); +} + +static void StrictNamesCheck(RestoreOptions *ropt) { const char *missing_name; @@ -2814,9 +2829,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH) teReqs res = REQ_SCHEMA | REQ_DATA; RestoreOptions *ropt = AH->public.ropt; - /* ENCODING and STDSTRINGS items are treated specially */ + /* These items are treated specially */ if (strcmp(te->desc, "ENCODING") == 0 || - strcmp(te->desc, "STDSTRINGS") == 0) + strcmp(te->desc, "STDSTRINGS") == 0 || + strcmp(te->desc, "SEARCHPATH") == 0) return REQ_SPECIAL; /* @@ -3117,6 +3133,10 @@ _doSetFixedOutputState(ArchiveHandle *AH) if (ropt && ropt->use_role) ahprintf(AH, "SET ROLE %s;\n", fmtId(ropt->use_role)); + /* Select the dump-time search_path */ + if (AH->public.searchpath) + ahprintf(AH, "%s", AH->public.searchpath); + /* Make sure function checking is disabled */ ahprintf(AH, "SET check_function_bodies = false;\n"); @@ -3321,6 +3341,15 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName) { PQExpBuffer qry; + /* + * If there was a SEARCHPATH TOC entry, we're supposed to just stay with + * that search_path rather than switching to entry-specific paths. + * Otherwise, it's an old archive that will not restore correctly unless + * we set the search_path as it's expecting. + */ + if (AH->public.searchpath) + return; + if (!schemaName || *schemaName == '\0' || (AH->currSchema && strcmp(AH->currSchema, schemaName) == 0)) return; /* no need to do anything */ @@ -3453,8 +3482,10 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH) strcmp(type, "SUBSCRIPTION") == 0 || strcmp(type, "USER MAPPING") == 0) { - /* We already know that search_path was set properly */ - appendPQExpBuffer(buf, "%s %s", type, fmtId(te->tag)); + appendPQExpBuffer(buf, "%s ", type); + if (te->namespace && *te->namespace) + appendPQExpBuffer(buf, "%s.", fmtId(te->namespace)); + appendPQExpBufferStr(buf, fmtId(te->tag)); return; } diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index becfee6e819..8dd19159989 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -92,10 +92,12 @@ typedef z_stream *z_streamp; * indicator */ #define K_VERS_1_12 MAKE_ARCHIVE_VERSION(1, 12, 0) /* add separate BLOB * entries */ +#define K_VERS_1_13 MAKE_ARCHIVE_VERSION(1, 13, 0) /* change search_path + * behavior */ /* Current archive version number (the format we can output) */ #define K_VERS_MAJOR 1 -#define K_VERS_MINOR 12 +#define K_VERS_MINOR 13 #define K_VERS_REV 0 #define K_VERS_SELF MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index f7a079f0b1d..8b67ec1aa1d 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -132,6 +132,15 @@ char g_comment_end[10]; static const CatalogId nilCatalogId = {0, 0}; +/* + * Macro for producing quoted, schema-qualified name of a dumpable object. + * Note implicit dependence on "fout"; we should get rid of that argument. + */ +#define fmtQualifiedDumpable(obj) \ + fmtQualifiedId(fout->remoteVersion, \ + (obj)->dobj.namespace->dobj.name, \ + (obj)->dobj.name) + static void help(const char *progname); static void setup_connection(Archive *AH, const char *dumpencoding, const char *dumpsnapshot, @@ -149,13 +158,13 @@ static NamespaceInfo *findNamespace(Archive *fout, Oid nsoid); static void dumpTableData(Archive *fout, TableDataInfo *tdinfo); static void refreshMatViewData(Archive *fout, TableDataInfo *tdinfo); static void guessConstraintInheritance(TableInfo *tblinfo, int numTables); -static void dumpComment(Archive *fout, const char *target, +static void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId); static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items); static int collectComments(Archive *fout, CommentItem **items); -static void dumpSecLabel(Archive *fout, const char *target, +static void dumpSecLabel(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId); static int findSecLabels(Archive *fout, Oid classoid, Oid objoid, @@ -210,7 +219,7 @@ static void dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo); static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, - const char *tag, const char *nspname, const char *owner, + const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls); @@ -239,10 +248,9 @@ static char *format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes); static char *convertRegProcReference(Archive *fout, const char *proc); -static char *convertOperatorReference(Archive *fout, const char *opr); +static char *getFormattedOperatorName(Archive *fout, const char *oproid); static char *convertTSFunction(Archive *fout, Oid funcOid); static Oid findLastBuiltinOid_V71(Archive *fout, const char *); -static void selectSourceSchema(Archive *fout, const char *schemaName); static char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts); static void getBlobs(Archive *fout); static void dumpBlob(Archive *fout, BlobInfo *binfo); @@ -256,6 +264,7 @@ static void dumpDatabaseConfig(Archive *AH, PQExpBuffer outbuf, const char *dbname, Oid dboid); static void dumpEncoding(Archive *AH); static void dumpStdStrings(Archive *AH); +static void dumpSearchPath(Archive *AH); static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, @@ -267,7 +276,9 @@ static void binary_upgrade_set_pg_class_oids(Archive *fout, Oid pg_class_oid, bool is_index); static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, - const char *objlabel); + const char *objtype, + const char *objname, + const char *objnamespace); static const char *getAttrName(int attrnum, TableInfo *tblInfo); static const char *fmtCopyColumnList(const TableInfo *ti, PQExpBuffer buffer); static bool nonemptyReloptions(const char *reloptions); @@ -844,9 +855,10 @@ main(int argc, char **argv) * order. */ - /* First the special ENCODING and STDSTRINGS entries. */ + /* First the special ENCODING, STDSTRINGS, and SEARCHPATH entries. */ dumpEncoding(fout); dumpStdStrings(fout); + dumpSearchPath(fout); /* The database items are always next, unless we don't want them at all */ if (dopt.outputCreateDB) @@ -1734,14 +1746,6 @@ dumpTableData_copy(Archive *fout, void *dcontext) tbinfo->dobj.namespace->dobj.name, classname); /* - * Make sure we are in proper schema. We will qualify the table name - * below anyway (in case its name conflicts with a pg_catalog table); but - * this ensures reproducible results in case the table contains regproc, - * regclass, etc columns. - */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - - /* * Specify the column list explicitly so that we have no possibility of * retrieving data in the wrong column order. (The default column * ordering of COPY will not be what we want in certain corner cases @@ -1752,9 +1756,7 @@ dumpTableData_copy(Archive *fout, void *dcontext) if (oids && hasoids) { appendPQExpBuffer(q, "COPY %s %s WITH OIDS TO stdout;", - fmtQualifiedId(fout->remoteVersion, - tbinfo->dobj.namespace->dobj.name, - classname), + fmtQualifiedDumpable(tbinfo), column_list); } else if (tdinfo->filtercond) @@ -1770,17 +1772,13 @@ dumpTableData_copy(Archive *fout, void *dcontext) else appendPQExpBufferStr(q, "* "); appendPQExpBuffer(q, "FROM %s %s) TO stdout;", - fmtQualifiedId(fout->remoteVersion, - tbinfo->dobj.namespace->dobj.name, - classname), + fmtQualifiedDumpable(tbinfo), tdinfo->filtercond); } else { appendPQExpBuffer(q, "COPY %s %s TO stdout;", - fmtQualifiedId(fout->remoteVersion, - tbinfo->dobj.namespace->dobj.name, - classname), + fmtQualifiedDumpable(tbinfo), column_list); } res = ExecuteSqlQuery(fout, q->data, PGRES_COPY_OUT); @@ -1890,7 +1888,6 @@ dumpTableData_insert(Archive *fout, void *dcontext) { TableDataInfo *tdinfo = (TableDataInfo *) dcontext; TableInfo *tbinfo = tdinfo->tdtable; - const char *classname = tbinfo->dobj.name; DumpOptions *dopt = fout->dopt; PQExpBuffer q = createPQExpBuffer(); PQExpBuffer insertStmt = NULL; @@ -1899,19 +1896,9 @@ dumpTableData_insert(Archive *fout, void *dcontext) int nfields; int field; - /* - * Make sure we are in proper schema. We will qualify the table name - * below anyway (in case its name conflicts with a pg_catalog table); but - * this ensures reproducible results in case the table contains regproc, - * regclass, etc columns. - */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR " "SELECT * FROM ONLY %s", - fmtQualifiedId(fout->remoteVersion, - tbinfo->dobj.namespace->dobj.name, - classname)); + fmtQualifiedDumpable(tbinfo)); if (tdinfo->filtercond) appendPQExpBuffer(q, " %s", tdinfo->filtercond); @@ -1933,6 +1920,8 @@ dumpTableData_insert(Archive *fout, void *dcontext) */ if (insertStmt == NULL) { + TableInfo *targettab; + insertStmt = createPQExpBuffer(); /* @@ -1941,25 +1930,12 @@ dumpTableData_insert(Archive *fout, void *dcontext) * through the root table. */ if (dopt->load_via_partition_root && tbinfo->ispartition) - { - TableInfo *parentTbinfo; - - parentTbinfo = getRootTableInfo(tbinfo); - - /* - * When we loading data through the root, we will qualify - * the table name. This is needed because earlier - * search_path will be set for the partition table. - */ - classname = (char *) fmtQualifiedId(fout->remoteVersion, - parentTbinfo->dobj.namespace->dobj.name, - parentTbinfo->dobj.name); - } + targettab = getRootTableInfo(tbinfo); else - classname = fmtId(tbinfo->dobj.name); + targettab = tbinfo; appendPQExpBuffer(insertStmt, "INSERT INTO %s ", - classname); + fmtQualifiedDumpable(targettab)); /* corner case for zero-column table */ if (nfields == 0) @@ -2135,17 +2111,10 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo) TableInfo *parentTbinfo; parentTbinfo = getRootTableInfo(tbinfo); - - /* - * When we load data through the root, we will qualify the table - * name, because search_path is set for the partition. - */ - copyFrom = fmtQualifiedId(fout->remoteVersion, - parentTbinfo->dobj.namespace->dobj.name, - parentTbinfo->dobj.name); + copyFrom = fmtQualifiedDumpable(parentTbinfo); } else - copyFrom = fmtId(tbinfo->dobj.name); + copyFrom = fmtQualifiedDumpable(tbinfo); /* must use 2 steps here 'cause fmtId is nonreentrant */ appendPQExpBuffer(copyBuf, "COPY %s ", @@ -2200,7 +2169,7 @@ refreshMatViewData(Archive *fout, TableDataInfo *tdinfo) q = createPQExpBuffer(); appendPQExpBuffer(q, "REFRESH MATERIALIZED VIEW %s;\n", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); if (tdinfo->dobj.dump & DUMP_COMPONENT_DATA) ArchiveEntry(fout, @@ -2328,9 +2297,6 @@ buildMatViewRefreshDependencies(Archive *fout) if (fout->remoteVersion < 90300) return; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - query = createPQExpBuffer(); appendPQExpBufferStr(query, "WITH RECURSIVE w AS " @@ -2592,9 +2558,6 @@ dumpDatabase(Archive *fout) if (g_verbose) write_msg(NULL, "saving database definition\n"); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* Fetch the database-level properties for this database */ if (fout->remoteVersion >= 90600) { @@ -2770,7 +2733,7 @@ dumpDatabase(Archive *fout) NULL, /* Dumper */ NULL); /* Dumper Arg */ - /* Compute correct tag for comments etc */ + /* Compute correct tag for archive entry */ appendPQExpBuffer(labelq, "DATABASE %s", qdatname); /* Dump DB comment if any */ @@ -2805,7 +2768,7 @@ dumpDatabase(Archive *fout) } else { - dumpComment(fout, labelq->data, NULL, dba, + dumpComment(fout, "DATABASE", qdatname, NULL, dba, dbCatId, 0, dbDumpId); } @@ -2837,7 +2800,7 @@ dumpDatabase(Archive *fout) * (pg_init_privs) on databases. */ dumpACL(fout, dbCatId, dbDumpId, "DATABASE", - qdatname, NULL, labelq->data, NULL, + qdatname, NULL, NULL, dba, datacl, rdatacl, "", ""); /* @@ -3125,6 +3088,69 @@ dumpStdStrings(Archive *AH) destroyPQExpBuffer(qry); } +/* + * dumpSearchPath: record the active search_path in the archive + */ +static void +dumpSearchPath(Archive *AH) +{ + PQExpBuffer qry = createPQExpBuffer(); + PQExpBuffer path = createPQExpBuffer(); + PGresult *res; + char **schemanames = NULL; + int nschemanames = 0; + int i; + + /* + * We use the result of current_schemas(), not the search_path GUC, + * because that might contain wildcards such as "$user", which won't + * necessarily have the same value during restore. Also, this way avoids + * listing schemas that may appear in search_path but not actually exist, + * which seems like a prudent exclusion. + */ + res = ExecuteSqlQueryForSingleRow(AH, + "SELECT pg_catalog.current_schemas(false)"); + + if (!parsePGArray(PQgetvalue(res, 0, 0), &schemanames, &nschemanames)) + exit_horribly(NULL, "could not parse result of current_schemas()\n"); + + /* + * We use set_config(), not a simple "SET search_path" command, because + * the latter has less-clean behavior if the search path is empty. While + * that's likely to get fixed at some point, it seems like a good idea to + * be as backwards-compatible as possible in what we put into archives. + */ + for (i = 0; i < nschemanames; i++) + { + if (i > 0) + appendPQExpBufferStr(path, ", "); + appendPQExpBufferStr(path, fmtId(schemanames[i])); + } + + appendPQExpBufferStr(qry, "SELECT pg_catalog.set_config('search_path', "); + appendStringLiteralAH(qry, path->data, AH); + appendPQExpBufferStr(qry, ", false);\n"); + + if (g_verbose) + write_msg(NULL, "saving search_path = %s\n", path->data); + + ArchiveEntry(AH, nilCatalogId, createDumpId(), + "SEARCHPATH", NULL, NULL, "", + false, "SEARCHPATH", SECTION_PRE_DATA, + qry->data, "", NULL, + NULL, 0, + NULL, NULL); + + /* Also save it in AH->searchpath, in case we're doing plain text dump */ + AH->searchpath = pg_strdup(qry->data); + + if (schemanames) + free(schemanames); + PQclear(res); + destroyPQExpBuffer(qry); + destroyPQExpBuffer(path); +} + /* * getBlobs: @@ -3151,9 +3177,6 @@ getBlobs(Archive *fout) if (g_verbose) write_msg(NULL, "reading large objects\n"); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* Fetch BLOB OIDs, and owner/ACL data if >= 9.0 */ if (fout->remoteVersion >= 90600) { @@ -3300,26 +3323,22 @@ dumpBlob(Archive *fout, BlobInfo *binfo) NULL, 0, NULL, NULL); - /* set up tag for comment and/or ACL */ - resetPQExpBuffer(cquery); - appendPQExpBuffer(cquery, "LARGE OBJECT %s", binfo->dobj.name); - /* Dump comment if any */ if (binfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, cquery->data, + dumpComment(fout, "LARGE OBJECT", binfo->dobj.name, NULL, binfo->rolname, binfo->dobj.catId, 0, binfo->dobj.dumpId); /* Dump security label if any */ if (binfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, cquery->data, + dumpSecLabel(fout, "LARGE OBJECT", binfo->dobj.name, NULL, binfo->rolname, binfo->dobj.catId, 0, binfo->dobj.dumpId); /* Dump ACL if any */ if (binfo->blobacl && (binfo->dobj.dump & DUMP_COMPONENT_ACL)) dumpACL(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT", - binfo->dobj.name, NULL, cquery->data, + binfo->dobj.name, NULL, NULL, binfo->rolname, binfo->blobacl, binfo->rblobacl, binfo->initblobacl, binfo->initrblobacl); @@ -3346,9 +3365,6 @@ dumpBlobs(Archive *fout, void *arg) if (g_verbose) write_msg(NULL, "saving large objects\n"); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* * Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning * the already-in-memory dumpable objects instead... @@ -3478,11 +3494,6 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.name); - /* - * select table schema to ensure regproc name is qualified if needed - */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - resetPQExpBuffer(query); /* Get the policies for the table. */ @@ -3595,7 +3606,7 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo) query = createPQExpBuffer(); appendPQExpBuffer(query, "ALTER TABLE %s ENABLE ROW LEVEL SECURITY;", - fmtId(polinfo->dobj.name)); + fmtQualifiedDumpable(polinfo)); if (polinfo->dobj.dump & DUMP_COMPONENT_POLICY) ArchiveEntry(fout, polinfo->dobj.catId, polinfo->dobj.dumpId, @@ -3634,7 +3645,7 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo) appendPQExpBuffer(query, "CREATE POLICY %s", fmtId(polinfo->polname)); - appendPQExpBuffer(query, " ON %s%s%s", fmtId(tbinfo->dobj.name), + appendPQExpBuffer(query, " ON %s%s%s", fmtQualifiedDumpable(tbinfo), !polinfo->polpermissive ? " AS RESTRICTIVE" : "", cmd); if (polinfo->polroles != NULL) @@ -3649,7 +3660,7 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo) appendPQExpBuffer(query, ";\n"); appendPQExpBuffer(delqry, "DROP POLICY %s", fmtId(polinfo->polname)); - appendPQExpBuffer(delqry, " ON %s;\n", fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delqry, " ON %s;\n", fmtQualifiedDumpable(tbinfo)); tag = psprintf("%s %s", tbinfo->dobj.name, polinfo->dobj.name); @@ -3698,9 +3709,6 @@ getPublications(Archive *fout) resetPQExpBuffer(query); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* Get the publications. */ appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, p.pubname, " @@ -3763,7 +3771,7 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo) { PQExpBuffer delq; PQExpBuffer query; - PQExpBuffer labelq; + char *qpubname; bool first = true; if (!(pubinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)) @@ -3771,15 +3779,14 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo) delq = createPQExpBuffer(); query = createPQExpBuffer(); - labelq = createPQExpBuffer(); + + qpubname = pg_strdup(fmtId(pubinfo->dobj.name)); appendPQExpBuffer(delq, "DROP PUBLICATION %s;\n", - fmtId(pubinfo->dobj.name)); + qpubname); appendPQExpBuffer(query, "CREATE PUBLICATION %s", - fmtId(pubinfo->dobj.name)); - - appendPQExpBuffer(labelq, "PUBLICATION %s", fmtId(pubinfo->dobj.name)); + qpubname); if (pubinfo->puballtables) appendPQExpBufferStr(query, " FOR ALL TABLES"); @@ -3822,17 +3829,18 @@ dumpPublication(Archive *fout, PublicationInfo *pubinfo) NULL, NULL); if (pubinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "PUBLICATION", qpubname, NULL, pubinfo->rolname, pubinfo->dobj.catId, 0, pubinfo->dobj.dumpId); if (pubinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "PUBLICATION", qpubname, NULL, pubinfo->rolname, pubinfo->dobj.catId, 0, pubinfo->dobj.dumpId); destroyPQExpBuffer(delq); destroyPQExpBuffer(query); + free(qpubname); } /* @@ -3857,9 +3865,6 @@ getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - for (i = 0; i < numTables; i++) { TableInfo *tbinfo = &tblinfo[i]; @@ -3948,8 +3953,8 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo) appendPQExpBuffer(query, "ALTER PUBLICATION %s ADD TABLE ONLY", fmtId(pubrinfo->pubname)); - appendPQExpBuffer(query, " %s;", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(query, " %s;\n", + fmtQualifiedDumpable(tbinfo)); /* * There is no point in creating drop query as drop query as the drop is @@ -4011,9 +4016,6 @@ getSubscriptions(Archive *fout) if (dopt->no_subscriptions || fout->remoteVersion < 100000) return; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (!is_superuser(fout)) { int n; @@ -4099,8 +4101,8 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo) { PQExpBuffer delq; PQExpBuffer query; - PQExpBuffer labelq; PQExpBuffer publications; + char *qsubname; char **pubnames = NULL; int npubnames = 0; int i; @@ -4110,13 +4112,14 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo) delq = createPQExpBuffer(); query = createPQExpBuffer(); - labelq = createPQExpBuffer(); + + qsubname = pg_strdup(fmtId(subinfo->dobj.name)); appendPQExpBuffer(delq, "DROP SUBSCRIPTION %s;\n", - fmtId(subinfo->dobj.name)); + qsubname); appendPQExpBuffer(query, "CREATE SUBSCRIPTION %s CONNECTION ", - fmtId(subinfo->dobj.name)); + qsubname); appendStringLiteralAH(query, subinfo->subconninfo, fout); /* Build list of quoted publications and append them to query. */ @@ -4150,8 +4153,6 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo) appendPQExpBufferStr(query, ");\n"); - appendPQExpBuffer(labelq, "SUBSCRIPTION %s", fmtId(subinfo->dobj.name)); - ArchiveEntry(fout, subinfo->dobj.catId, subinfo->dobj.dumpId, subinfo->dobj.name, NULL, @@ -4163,12 +4164,12 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo) NULL, NULL); if (subinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "SUBSCRIPTION", qsubname, NULL, subinfo->rolname, subinfo->dobj.catId, 0, subinfo->dobj.dumpId); if (subinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "SUBSCRIPTION", qsubname, NULL, subinfo->rolname, subinfo->dobj.catId, 0, subinfo->dobj.dumpId); @@ -4178,6 +4179,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo) destroyPQExpBuffer(delq); destroyPQExpBuffer(query); + free(qsubname); } static void @@ -4361,11 +4363,16 @@ binary_upgrade_set_pg_class_oids(Archive *fout, /* * If the DumpableObject is a member of an extension, add a suitable * ALTER EXTENSION ADD command to the creation commands in upgrade_buffer. + * + * For somewhat historical reasons, objname should already be quoted, + * but not objnamespace (if any). */ static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, - const char *objlabel) + const char *objtype, + const char *objname, + const char *objnamespace) { DumpableObject *extobj = NULL; int i; @@ -4387,13 +4394,17 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, extobj = NULL; } if (extobj == NULL) - exit_horribly(NULL, "could not find parent extension for %s\n", objlabel); + exit_horribly(NULL, "could not find parent extension for %s %s\n", + objtype, objname); appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, handle extension membership the hard way\n"); - appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n", + appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s ", fmtId(extobj->name), - objlabel); + objtype); + if (objnamespace && *objnamespace) + appendPQExpBuffer(upgrade_buffer, "%s.", fmtId(objnamespace)); + appendPQExpBuffer(upgrade_buffer, "%s;\n", objname); } /* @@ -4423,9 +4434,6 @@ getNamespaces(Archive *fout, int *numNamespaces) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* * we fetch all namespaces including system ones, so that every object we * read in can be linked to a containing namespace. @@ -4581,9 +4589,6 @@ getExtensions(Archive *fout, int *numExtensions) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, " "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition " "FROM pg_extension x " @@ -4681,9 +4686,6 @@ getTypes(Archive *fout, int *numTypes) * be revisited if the backend ever allows renaming of array types. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 90600) { PQExpBuffer acl_subquery = createPQExpBuffer(); @@ -4913,9 +4915,6 @@ getOperators(Archive *fout, int *numOprs) * system-defined operators at dump-out time. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " "oprnamespace, " "(%s oprowner) AS rolname, " @@ -5006,9 +5005,6 @@ getCollations(Archive *fout, int *numCollations) * system-defined collations at dump-out time. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, collname, " "collnamespace, " "(%s collowner) AS rolname " @@ -5082,9 +5078,6 @@ getConversions(Archive *fout, int *numConversions) * system-defined conversions at dump-out time. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " "connamespace, " "(%s conowner) AS rolname " @@ -5160,9 +5153,6 @@ getAccessMethods(Archive *fout, int *numAccessMethods) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* Select all access methods from pg_am table */ appendPQExpBuffer(query, "SELECT tableoid, oid, amname, amtype, " "amhandler::pg_catalog.regproc AS amhandler " @@ -5233,9 +5223,6 @@ getOpclasses(Archive *fout, int *numOpclasses) * system-defined opclasses at dump-out time. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, " "opcnamespace, " "(%s opcowner) AS rolname " @@ -5320,9 +5307,6 @@ getOpfamilies(Archive *fout, int *numOpfamilies) * system-defined opfamilies at dump-out time. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, " "opfnamespace, " "(%s opfowner) AS rolname " @@ -5400,9 +5384,6 @@ getAggregates(Archive *fout, int *numAggs) int i_initaggacl; int i_initraggacl; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. @@ -5594,9 +5575,6 @@ getFuncs(Archive *fout, int *numFuncs) int i_initproacl; int i_initrproacl; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* * Find all interesting functions. This is a bit complicated: * @@ -5853,9 +5831,6 @@ getTables(Archive *fout, int *numTables) int i_ispartition; int i_partbound; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* * Find all the tables and table-like objects. * @@ -6562,9 +6537,7 @@ getTables(Archive *fout, int *numTables) resetPQExpBuffer(query); appendPQExpBuffer(query, "LOCK TABLE %s IN ACCESS SHARE MODE", - fmtQualifiedId(fout->remoteVersion, - tblinfo[i].dobj.namespace->dobj.name, - tblinfo[i].dobj.name)); + fmtQualifiedDumpable(&tblinfo[i])); ExecuteSqlStatement(fout, query->data); } @@ -6656,9 +6629,6 @@ getInherits(Archive *fout, int *numInherits) int i_inhrelid; int i_inhparent; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - /* * Find all the inheritance information, excluding implicit inheritance * via partitioning. We handle that case using getPartitions(), because @@ -6750,9 +6720,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.name); - /* Make sure we are in proper schema so indexdef is right */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - /* * The point of the messy-looking outer join is to find a constraint * that is related by an internal dependency link to the index. If we @@ -7046,9 +7013,6 @@ getExtendedStatistics(Archive *fout) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, " "stxnamespace, (%s stxowner) AS rolname " "FROM pg_catalog.pg_statistic_ext", @@ -7128,12 +7092,6 @@ getConstraints(Archive *fout, TableInfo tblinfo[], int numTables) tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.name); - /* - * select table schema to ensure constraint expr is qualified if - * needed - */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - resetPQExpBuffer(query); appendPQExpBuffer(query, "SELECT tableoid, oid, conname, confrelid, " @@ -7198,12 +7156,6 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo) i_consrc; int ntups; - /* - * select appropriate schema to ensure names in constraint are properly - * qualified - */ - selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name); - query = createPQExpBuffer(); if (fout->remoteVersion >= 90100) @@ -7298,9 +7250,6 @@ getRules(Archive *fout, int *numRules) int i_is_instead; int i_ev_enabled; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 80300) { appendPQExpBufferStr(query, "SELECT " @@ -7436,11 +7385,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.name); - /* - * select table schema to ensure regproc name is qualified if needed - */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - resetPQExpBuffer(query); if (fout->remoteVersion >= 90000) { @@ -7624,9 +7568,6 @@ getEventTriggers(Archive *fout, int *numEventTriggers) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT e.tableoid, e.oid, evtname, evtenabled, " "evtevent, (%s evtowner) AS evtowner, " @@ -7714,9 +7655,6 @@ getProcLangs(Archive *fout, int *numProcLangs) int i_initrlanacl; int i_lanowner; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 90600) { PQExpBuffer acl_subquery = createPQExpBuffer(); @@ -7889,9 +7827,6 @@ getCasts(Archive *fout, int *numCasts) int i_castcontext; int i_castmethod; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 80400) { appendPQExpBufferStr(query, "SELECT tableoid, oid, " @@ -8013,9 +7948,6 @@ getTransforms(Archive *fout, int *numTransforms) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, " "trftype, trflang, trffromsql::oid, trftosql::oid " "FROM pg_transform " @@ -8129,12 +8061,6 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) if (!tbinfo->interesting) continue; - /* - * Make sure we are in proper schema for this table; this allows - * correct retrieval of formatted type names and default exprs - */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - /* find all the user attributes and their types */ /* @@ -8609,9 +8535,6 @@ getTSParsers(Archive *fout, int *numTSParsers) * system-defined objects at dump-out time. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, " "prsstart::oid, prstoken::oid, " "prsend::oid, prsheadline::oid, prslextype::oid " @@ -8696,9 +8619,6 @@ getTSDictionaries(Archive *fout, int *numTSDicts) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, dictname, " "dictnamespace, (%s dictowner) AS rolname, " "dicttemplate, dictinitoption " @@ -8782,9 +8702,6 @@ getTSTemplates(Archive *fout, int *numTSTemplates) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, " "tmplnamespace, tmplinit::oid, tmpllexize::oid " "FROM pg_ts_template"); @@ -8861,9 +8778,6 @@ getTSConfigurations(Archive *fout, int *numTSConfigs) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT tableoid, oid, cfgname, " "cfgnamespace, (%s cfgowner) AS rolname, cfgparser " "FROM pg_ts_config", @@ -8947,9 +8861,6 @@ getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 90600) { PQExpBuffer acl_subquery = createPQExpBuffer(); @@ -9117,9 +9028,6 @@ getForeignServers(Archive *fout, int *numForeignServers) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 90600) { PQExpBuffer acl_subquery = createPQExpBuffer(); @@ -9266,9 +9174,6 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs) query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 90600) { PQExpBuffer acl_subquery = createPQExpBuffer(); @@ -9369,13 +9274,18 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs) * dumpComment -- * * This routine is used to dump any comments associated with the - * object handed to this routine. The routine takes a constant character - * string for the target part of the comment-creation command, plus + * object handed to this routine. The routine takes the object type + * and object name (ready to print, except for schema decoration), plus * the namespace and owner of the object (for labeling the ArchiveEntry), * plus catalog ID and subid which are the lookup key for pg_description, * plus the dump ID for the object (for setting a dependency). * If a matching pg_description entry is found, it is dumped. * + * Note: in some cases, such as comments for triggers and rules, the "type" + * string really looks like, e.g., "TRIGGER name ON". This is a bit of a hack + * but it doesn't seem worth complicating the API for all callers to make + * it cleaner. + * * Note: although this routine takes a dumpId for dependency purposes, * that purpose is just to mark the dependency in the emitted dump file * for possible future use by pg_restore. We do NOT use it for determining @@ -9384,7 +9294,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs) * calling ArchiveEntry() for the specified object. */ static void -dumpComment(Archive *fout, const char *target, +dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId) { @@ -9397,7 +9307,7 @@ dumpComment(Archive *fout, const char *target, return; /* Comments are schema not data ... except blob comments are data */ - if (strncmp(target, "LARGE OBJECT ", 13) != 0) + if (strcmp(type, "LARGE OBJECT") != 0) { if (dopt->dataOnly) return; @@ -9426,24 +9336,31 @@ dumpComment(Archive *fout, const char *target, if (ncomments > 0) { PQExpBuffer query = createPQExpBuffer(); + PQExpBuffer tag = createPQExpBuffer(); - appendPQExpBuffer(query, "COMMENT ON %s IS ", target); + appendPQExpBuffer(query, "COMMENT ON %s ", type); + if (namespace && *namespace) + appendPQExpBuffer(query, "%s.", fmtId(namespace)); + appendPQExpBuffer(query, "%s IS ", name); appendStringLiteralAH(query, comments->descr, fout); appendPQExpBufferStr(query, ";\n"); + appendPQExpBuffer(tag, "%s %s", type, name); + /* * We mark comments as SECTION_NONE because they really belong in the * same section as their parent, whether that is pre-data or * post-data. */ ArchiveEntry(fout, nilCatalogId, createDumpId(), - target, namespace, NULL, owner, + tag->data, namespace, NULL, owner, false, "COMMENT", SECTION_NONE, query->data, "", NULL, &(dumpId), 1, NULL, NULL); destroyPQExpBuffer(query); + destroyPQExpBuffer(tag); } } @@ -9461,7 +9378,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, CommentItem *comments; int ncomments; PQExpBuffer query; - PQExpBuffer target; + PQExpBuffer tag; /* do nothing, if --no-comments is supplied */ if (dopt->no_comments) @@ -9482,7 +9399,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, return; query = createPQExpBuffer(); - target = createPQExpBuffer(); + tag = createPQExpBuffer(); while (ncomments > 0) { @@ -9491,17 +9408,18 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, if (objsubid == 0) { - resetPQExpBuffer(target); - appendPQExpBuffer(target, "%s %s", reltypename, + resetPQExpBuffer(tag); + appendPQExpBuffer(tag, "%s %s", reltypename, fmtId(tbinfo->dobj.name)); resetPQExpBuffer(query); - appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); + appendPQExpBuffer(query, "COMMENT ON %s %s IS ", reltypename, + fmtQualifiedDumpable(tbinfo)); appendStringLiteralAH(query, descr, fout); appendPQExpBufferStr(query, ";\n"); ArchiveEntry(fout, nilCatalogId, createDumpId(), - target->data, + tag->data, tbinfo->dobj.namespace->dobj.name, NULL, tbinfo->rolname, false, "COMMENT", SECTION_NONE, @@ -9511,18 +9429,21 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, } else if (objsubid > 0 && objsubid <= tbinfo->numatts) { - resetPQExpBuffer(target); - appendPQExpBuffer(target, "COLUMN %s.", + resetPQExpBuffer(tag); + appendPQExpBuffer(tag, "COLUMN %s.", fmtId(tbinfo->dobj.name)); - appendPQExpBufferStr(target, fmtId(tbinfo->attnames[objsubid - 1])); + appendPQExpBufferStr(tag, fmtId(tbinfo->attnames[objsubid - 1])); resetPQExpBuffer(query); - appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); + appendPQExpBuffer(query, "COMMENT ON COLUMN %s.", + fmtQualifiedDumpable(tbinfo)); + appendPQExpBuffer(query, "%s IS ", + fmtId(tbinfo->attnames[objsubid - 1])); appendStringLiteralAH(query, descr, fout); appendPQExpBufferStr(query, ";\n"); ArchiveEntry(fout, nilCatalogId, createDumpId(), - target->data, + tag->data, tbinfo->dobj.namespace->dobj.name, NULL, tbinfo->rolname, false, "COMMENT", SECTION_NONE, @@ -9536,7 +9457,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, } destroyPQExpBuffer(query); - destroyPQExpBuffer(target); + destroyPQExpBuffer(tag); } /* @@ -9643,11 +9564,6 @@ collectComments(Archive *fout, CommentItem **items) int i; CommentItem *comments; - /* - * Note we do NOT change source schema here; preserve the caller's - * setting, instead. - */ - query = createPQExpBuffer(); appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid " @@ -9842,7 +9758,6 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; char *qnspname; /* Skip if not to be dumped */ @@ -9851,7 +9766,6 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); qnspname = pg_strdup(fmtId(nspinfo->dobj.name)); @@ -9859,10 +9773,9 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) appendPQExpBuffer(q, "CREATE SCHEMA %s;\n", qnspname); - appendPQExpBuffer(labelq, "SCHEMA %s", qnspname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &nspinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &nspinfo->dobj, + "SCHEMA", qnspname, NULL); if (nspinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId, @@ -9876,18 +9789,18 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) /* Dump Schema Comments and Security Labels */ if (nspinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "SCHEMA", qnspname, NULL, nspinfo->rolname, nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId); if (nspinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "SCHEMA", qnspname, NULL, nspinfo->rolname, nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId); if (nspinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId, "SCHEMA", - qnspname, NULL, labelq->data, NULL, + qnspname, NULL, NULL, nspinfo->rolname, nspinfo->nspacl, nspinfo->rnspacl, nspinfo->initnspacl, nspinfo->initrnspacl); @@ -9895,7 +9808,6 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); } /* @@ -9908,7 +9820,6 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; char *qextname; /* Skip if not to be dumped */ @@ -9917,7 +9828,6 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); qextname = pg_strdup(fmtId(extinfo->dobj.name)); @@ -10003,8 +9913,6 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) appendPQExpBufferStr(q, ");\n"); } - appendPQExpBuffer(labelq, "EXTENSION %s", qextname); - if (extinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, extinfo->dobj.catId, extinfo->dobj.dumpId, extinfo->dobj.name, @@ -10017,12 +9925,12 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) /* Dump Extension Comments and Security Labels */ if (extinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "EXTENSION", qextname, NULL, "", extinfo->dobj.catId, 0, extinfo->dobj.dumpId); if (extinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "EXTENSION", qextname, NULL, "", extinfo->dobj.catId, 0, extinfo->dobj.dumpId); @@ -10030,7 +9938,6 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); } /* @@ -10074,18 +9981,15 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer(); PGresult *res; int num, i; Oid enum_oid; char *qtypname; + char *qualtypname; char *label; - /* Set proper schema search path */ - selectSourceSchema(fout, "pg_catalog"); - if (fout->remoteVersion >= 90100) appendPQExpBuffer(query, "SELECT oid, enumlabel " "FROM pg_catalog.pg_enum " @@ -10104,16 +10008,13 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) num = PQntuples(res); qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); + qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo)); /* - * DROP must be fully qualified in case same name appears in pg_catalog. * CASCADE shouldn't be required here as for normal types since the I/O * functions are generic and do not get dropped. */ - appendPQExpBuffer(delq, "DROP TYPE %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - qtypname); + appendPQExpBuffer(delq, "DROP TYPE %s;\n", qualtypname); if (dopt->binary_upgrade) binary_upgrade_set_type_oids_by_type_oid(fout, q, @@ -10121,7 +10022,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) false); appendPQExpBuffer(q, "CREATE TYPE %s AS ENUM (", - qtypname); + qualtypname); if (!dopt->binary_upgrade) { @@ -10151,19 +10052,16 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) appendPQExpBuffer(q, "SELECT pg_catalog.binary_upgrade_set_next_pg_enum_oid('%u'::pg_catalog.oid);\n", enum_oid); - appendPQExpBuffer(q, "ALTER TYPE %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(q, "%s ADD VALUE ", - qtypname); + appendPQExpBuffer(q, "ALTER TYPE %s ADD VALUE ", qualtypname); appendStringLiteralAH(q, label, fout); appendPQExpBufferStr(q, ";\n\n"); } } - appendPQExpBuffer(labelq, "TYPE %s", qtypname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tyinfo->dobj, + "TYPE", qtypname, + tyinfo->dobj.namespace->dobj.name); if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, @@ -10178,18 +10076,18 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) /* Dump Type Comments and Security Labels */ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", - qtypname, NULL, labelq->data, + qtypname, NULL, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl, tyinfo->inittypacl, tyinfo->initrtypacl); @@ -10197,8 +10095,9 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) PQclear(res); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qtypname); + free(qualtypname); } /* @@ -10211,19 +10110,13 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer(); PGresult *res; Oid collationOid; char *qtypname; + char *qualtypname; char *procname; - /* - * select appropriate schema to ensure names in CREATE are properly - * qualified - */ - selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name); - appendPQExpBuffer(query, "SELECT pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, " "opc.opcname AS opcname, " @@ -10242,16 +10135,13 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) res = ExecuteSqlQueryForSingleRow(fout, query->data); qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); + qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo)); /* - * DROP must be fully qualified in case same name appears in pg_catalog. * CASCADE shouldn't be required here as for normal types since the I/O * functions are generic and do not get dropped. */ - appendPQExpBuffer(delq, "DROP TYPE %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - qtypname); + appendPQExpBuffer(delq, "DROP TYPE %s;\n", qualtypname); if (dopt->binary_upgrade) binary_upgrade_set_type_oids_by_type_oid(fout, q, @@ -10259,7 +10149,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) false); appendPQExpBuffer(q, "CREATE TYPE %s AS RANGE (", - qtypname); + qualtypname); appendPQExpBuffer(q, "\n subtype = %s", PQgetvalue(res, 0, PQfnumber(res, "rngsubtype"))); @@ -10270,7 +10160,6 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) char *opcname = PQgetvalue(res, 0, PQfnumber(res, "opcname")); char *nspname = PQgetvalue(res, 0, PQfnumber(res, "opcnsp")); - /* always schema-qualify, don't try to be smart */ appendPQExpBuffer(q, ",\n subtype_opclass = %s.", fmtId(nspname)); appendPQExpBufferStr(q, fmtId(opcname)); @@ -10282,12 +10171,8 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) CollInfo *coll = findCollationByOid(collationOid); if (coll) - { - /* always schema-qualify, don't try to be smart */ - appendPQExpBuffer(q, ",\n collation = %s.", - fmtId(coll->dobj.namespace->dobj.name)); - appendPQExpBufferStr(q, fmtId(coll->dobj.name)); - } + appendPQExpBuffer(q, ",\n collation = %s", + fmtQualifiedDumpable(coll)); } procname = PQgetvalue(res, 0, PQfnumber(res, "rngcanonical")); @@ -10300,10 +10185,10 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) appendPQExpBufferStr(q, "\n);\n"); - appendPQExpBuffer(labelq, "TYPE %s", qtypname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tyinfo->dobj, + "TYPE", qtypname, + tyinfo->dobj.namespace->dobj.name); if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, @@ -10318,18 +10203,18 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) /* Dump Type Comments and Security Labels */ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", - qtypname, NULL, labelq->data, + qtypname, NULL, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl, tyinfo->inittypacl, tyinfo->initrtypacl); @@ -10337,8 +10222,9 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) PQclear(res); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qtypname); + free(qualtypname); } /* @@ -10356,18 +10242,13 @@ dumpUndefinedType(Archive *fout, TypeInfo *tyinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); char *qtypname; + char *qualtypname; qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); + qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo)); - /* - * DROP must be fully qualified in case same name appears in pg_catalog. - */ - appendPQExpBuffer(delq, "DROP TYPE %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - qtypname); + appendPQExpBuffer(delq, "DROP TYPE %s;\n", qualtypname); if (dopt->binary_upgrade) binary_upgrade_set_type_oids_by_type_oid(fout, q, @@ -10375,12 +10256,12 @@ dumpUndefinedType(Archive *fout, TypeInfo *tyinfo) false); appendPQExpBuffer(q, "CREATE TYPE %s;\n", - qtypname); - - appendPQExpBuffer(labelq, "TYPE %s", qtypname); + qualtypname); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tyinfo->dobj, + "TYPE", qtypname, + tyinfo->dobj.namespace->dobj.name); if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, @@ -10395,25 +10276,26 @@ dumpUndefinedType(Archive *fout, TypeInfo *tyinfo) /* Dump Type Comments and Security Labels */ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", - qtypname, NULL, labelq->data, + qtypname, NULL, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl, tyinfo->inittypacl, tyinfo->initrtypacl); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qtypname); + free(qualtypname); } /* @@ -10426,10 +10308,10 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer(); PGresult *res; char *qtypname; + char *qualtypname; char *typlen; char *typinput; char *typoutput; @@ -10453,9 +10335,6 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) char *typdefault; bool typdefault_is_literal = false; - /* Set proper schema search path so regproc references list correctly */ - selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name); - /* Fetch type-specific details */ if (fout->remoteVersion >= 90100) { @@ -10564,17 +10443,14 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) typdefault = NULL; qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); + qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo)); /* - * DROP must be fully qualified in case same name appears in pg_catalog. * The reason we include CASCADE is that the circular dependency between * the type and its I/O functions makes it impossible to drop the type any * other way. */ - appendPQExpBuffer(delq, "DROP TYPE %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s CASCADE;\n", - qtypname); + appendPQExpBuffer(delq, "DROP TYPE %s CASCADE;\n", qualtypname); /* * We might already have a shell type, but setting pg_type_oid is @@ -10588,7 +10464,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) appendPQExpBuffer(q, "CREATE TYPE %s (\n" " INTERNALLENGTH = %s", - qtypname, + qualtypname, (strcmp(typlen, "-1") == 0) ? "variable" : typlen); /* regproc result is sufficiently quoted already */ @@ -10621,8 +10497,6 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) { char *elemType; - /* reselect schema in case changed by function dump */ - selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name); elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroAsOpaque); appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType); free(elemType); @@ -10666,10 +10540,10 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) appendPQExpBufferStr(q, "\n);\n"); - appendPQExpBuffer(labelq, "TYPE %s", qtypname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tyinfo->dobj, + "TYPE", qtypname, + tyinfo->dobj.namespace->dobj.name); if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, @@ -10684,18 +10558,18 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) /* Dump Type Comments and Security Labels */ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", - qtypname, NULL, labelq->data, + qtypname, NULL, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl, tyinfo->inittypacl, tyinfo->initrtypacl); @@ -10703,8 +10577,9 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) PQclear(res); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qtypname); + free(qualtypname); } /* @@ -10717,20 +10592,17 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer(); PGresult *res; int i; char *qtypname; + char *qualtypname; char *typnotnull; char *typdefn; char *typdefault; Oid typcollation; bool typdefault_is_literal = false; - /* Set proper schema search path so type references list correctly */ - selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name); - /* Fetch domain specific details */ if (fout->remoteVersion >= 90100) { @@ -10778,10 +10650,11 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) true); /* force array type */ qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); + qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo)); appendPQExpBuffer(q, "CREATE DOMAIN %s AS %s", - qtypname, + qualtypname, typdefn); /* Print collation only if different from base type's collation */ @@ -10791,12 +10664,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) coll = findCollationByOid(typcollation); if (coll) - { - /* always schema-qualify, don't try to be smart */ - appendPQExpBuffer(q, " COLLATE %s.", - fmtId(coll->dobj.namespace->dobj.name)); - appendPQExpBufferStr(q, fmtId(coll->dobj.name)); - } + appendPQExpBuffer(q, " COLLATE %s", fmtQualifiedDumpable(coll)); } if (typnotnull[0] == 't') @@ -10827,18 +10695,12 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) appendPQExpBufferStr(q, ";\n"); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP DOMAIN %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - qtypname); - - appendPQExpBuffer(labelq, "DOMAIN %s", qtypname); + appendPQExpBuffer(delq, "DROP DOMAIN %s;\n", qualtypname); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tyinfo->dobj, + "DOMAIN", qtypname, + tyinfo->dobj.namespace->dobj.name); if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, @@ -10853,18 +10715,18 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) /* Dump Domain Comments and Security Labels */ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "DOMAIN", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "DOMAIN", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", - qtypname, NULL, labelq->data, + qtypname, NULL, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl, tyinfo->inittypacl, tyinfo->initrtypacl); @@ -10873,26 +10735,25 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) for (i = 0; i < tyinfo->nDomChecks; i++) { ConstraintInfo *domcheck = &(tyinfo->domChecks[i]); - PQExpBuffer labelq = createPQExpBuffer(); + PQExpBuffer conprefix = createPQExpBuffer(); - appendPQExpBuffer(labelq, "CONSTRAINT %s ", + appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN", fmtId(domcheck->dobj.name)); - appendPQExpBuffer(labelq, "ON DOMAIN %s", - qtypname); if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, conprefix->data, qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, domcheck->dobj.catId, 0, tyinfo->dobj.dumpId); - destroyPQExpBuffer(labelq); + destroyPQExpBuffer(conprefix); } destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qtypname); + free(qualtypname); } /* @@ -10907,10 +10768,10 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) PQExpBuffer q = createPQExpBuffer(); PQExpBuffer dropped = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer(); PGresult *res; char *qtypname; + char *qualtypname; int ntups; int i_attname; int i_atttypdefn; @@ -10921,9 +10782,6 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) int i; int actual_atts; - /* Set proper schema search path so type references list correctly */ - selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name); - /* Fetch type specific details */ if (fout->remoteVersion >= 90100) { @@ -10983,9 +10841,10 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) } qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); + qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo)); appendPQExpBuffer(q, "CREATE TYPE %s AS (", - qtypname); + qualtypname); actual_atts = 0; for (i = 0; i < ntups; i++) @@ -11023,12 +10882,8 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) coll = findCollationByOid(attcollation); if (coll) - { - /* always schema-qualify, don't try to be smart */ - appendPQExpBuffer(q, " COLLATE %s.", - fmtId(coll->dobj.namespace->dobj.name)); - appendPQExpBufferStr(q, fmtId(coll->dobj.name)); - } + appendPQExpBuffer(q, " COLLATE %s", + fmtQualifiedDumpable(coll)); } } else @@ -11050,11 +10905,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) "WHERE attname = ", attlen, attalign); appendStringLiteralAH(dropped, attname, fout); appendPQExpBufferStr(dropped, "\n AND attrelid = "); - appendStringLiteralAH(dropped, qtypname, fout); + appendStringLiteralAH(dropped, qualtypname, fout); appendPQExpBufferStr(dropped, "::pg_catalog.regclass;\n"); appendPQExpBuffer(dropped, "ALTER TYPE %s ", - qtypname); + qualtypname); appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n", fmtId(attname)); } @@ -11062,18 +10917,12 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) appendPQExpBufferStr(q, "\n);\n"); appendPQExpBufferStr(q, dropped->data); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP TYPE %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - qtypname); - - appendPQExpBuffer(labelq, "TYPE %s", qtypname); + appendPQExpBuffer(delq, "DROP TYPE %s;\n", qualtypname); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tyinfo->dobj, + "TYPE", qtypname, + tyinfo->dobj.namespace->dobj.name); if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, @@ -11089,18 +10938,18 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) /* Dump Type Comments and Security Labels */ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "TYPE", qtypname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", - qtypname, NULL, labelq->data, + qtypname, NULL, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl, tyinfo->inittypacl, tyinfo->initrtypacl); @@ -11109,8 +10958,9 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) destroyPQExpBuffer(q); destroyPQExpBuffer(dropped); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qtypname); + free(qualtypname); /* Dump any per-column comments */ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT) @@ -11205,7 +11055,9 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo) appendPQExpBufferStr(target, fmtId(attname)); resetPQExpBuffer(query); - appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); + appendPQExpBuffer(query, "COMMENT ON COLUMN %s.", + fmtQualifiedDumpable(tyinfo)); + appendPQExpBuffer(query, "%s IS ", fmtId(attname)); appendStringLiteralAH(query, descr, fout); appendPQExpBufferStr(query, ";\n"); @@ -11261,7 +11113,7 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo) false); appendPQExpBuffer(q, "CREATE TYPE %s;\n", - fmtId(stinfo->dobj.name)); + fmtQualifiedDumpable(stinfo)); if (stinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, stinfo->dobj.catId, stinfo->dobj.dumpId, @@ -11288,10 +11140,8 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) DumpOptions *dopt = fout->dopt; PQExpBuffer defqry; PQExpBuffer delqry; - PQExpBuffer labelq; bool useParams; char *qlanname; - char *lanschema; FuncInfo *funcInfo; FuncInfo *inlineInfo = NULL; FuncInfo *validatorInfo = NULL; @@ -11337,20 +11187,9 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) defqry = createPQExpBuffer(); delqry = createPQExpBuffer(); - labelq = createPQExpBuffer(); qlanname = pg_strdup(fmtId(plang->dobj.name)); - /* - * If dumping a HANDLER clause, treat the language as being in the handler - * function's schema; this avoids cluttering the HANDLER clause. Otherwise - * it doesn't really have a schema. - */ - if (useParams) - lanschema = funcInfo->dobj.namespace->dobj.name; - else - lanschema = NULL; - appendPQExpBuffer(delqry, "DROP PROCEDURAL LANGUAGE %s;\n", qlanname); @@ -11360,25 +11199,13 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) plang->lanpltrusted ? "TRUSTED " : "", qlanname); appendPQExpBuffer(defqry, " HANDLER %s", - fmtId(funcInfo->dobj.name)); + fmtQualifiedDumpable(funcInfo)); if (OidIsValid(plang->laninline)) - { - appendPQExpBufferStr(defqry, " INLINE "); - /* Cope with possibility that inline is in different schema */ - if (inlineInfo->dobj.namespace != funcInfo->dobj.namespace) - appendPQExpBuffer(defqry, "%s.", - fmtId(inlineInfo->dobj.namespace->dobj.name)); - appendPQExpBufferStr(defqry, fmtId(inlineInfo->dobj.name)); - } + appendPQExpBuffer(defqry, " INLINE %s", + fmtQualifiedDumpable(inlineInfo)); if (OidIsValid(plang->lanvalidator)) - { - appendPQExpBufferStr(defqry, " VALIDATOR "); - /* Cope with possibility that validator is in different schema */ - if (validatorInfo->dobj.namespace != funcInfo->dobj.namespace) - appendPQExpBuffer(defqry, "%s.", - fmtId(validatorInfo->dobj.namespace->dobj.name)); - appendPQExpBufferStr(defqry, fmtId(validatorInfo->dobj.name)); - } + appendPQExpBuffer(defqry, " VALIDATOR %s", + fmtQualifiedDumpable(validatorInfo)); } else { @@ -11396,15 +11223,14 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) } appendPQExpBufferStr(defqry, ";\n"); - appendPQExpBuffer(labelq, "LANGUAGE %s", qlanname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(defqry, &plang->dobj, labelq->data); + binary_upgrade_extension_member(defqry, &plang->dobj, + "LANGUAGE", qlanname, NULL); if (plang->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId, plang->dobj.name, - lanschema, NULL, plang->lanowner, + NULL, NULL, plang->lanowner, false, "PROCEDURAL LANGUAGE", SECTION_PRE_DATA, defqry->data, delqry->data, NULL, NULL, 0, @@ -11412,19 +11238,18 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) /* Dump Proc Lang Comments and Security Labels */ if (plang->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, - lanschema, plang->lanowner, + dumpComment(fout, "LANGUAGE", qlanname, + NULL, plang->lanowner, plang->dobj.catId, 0, plang->dobj.dumpId); if (plang->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, - lanschema, plang->lanowner, + dumpSecLabel(fout, "LANGUAGE", qlanname, + NULL, plang->lanowner, plang->dobj.catId, 0, plang->dobj.dumpId); if (plang->lanpltrusted && plang->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, plang->dobj.catId, plang->dobj.dumpId, "LANGUAGE", - qlanname, NULL, labelq->data, - lanschema, + qlanname, NULL, NULL, plang->lanowner, plang->lanacl, plang->rlanacl, plang->initlanacl, plang->initrlanacl); @@ -11432,7 +11257,6 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) destroyPQExpBuffer(defqry); destroyPQExpBuffer(delqry); - destroyPQExpBuffer(labelq); } /* @@ -11576,7 +11400,6 @@ dumpFunc(Archive *fout, FuncInfo *finfo) PQExpBuffer query; PQExpBuffer q; PQExpBuffer delqry; - PQExpBuffer labelq; PQExpBuffer asPart; PGresult *res; char *funcsig; /* identity signature */ @@ -11620,12 +11443,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo) query = createPQExpBuffer(); q = createPQExpBuffer(); delqry = createPQExpBuffer(); - labelq = createPQExpBuffer(); asPart = createPQExpBuffer(); - /* Set proper schema search path so type references list correctly */ - selectSourceSchema(fout, finfo->dobj.namespace->dobj.name); - /* Fetch function-specific details */ if (fout->remoteVersion >= 90600) { @@ -11901,18 +11720,17 @@ dumpFunc(Archive *fout, FuncInfo *finfo) keyword = is_procedure ? "PROCEDURE" : "FUNCTION"; - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ appendPQExpBuffer(delqry, "DROP %s %s.%s;\n", keyword, fmtId(finfo->dobj.namespace->dobj.name), funcsig); - appendPQExpBuffer(q, "CREATE %s %s", + appendPQExpBuffer(q, "CREATE %s %s.%s", keyword, + fmtId(finfo->dobj.namespace->dobj.name), funcfullsig ? funcfullsig : funcsig); + if (is_procedure) ; else if (funcresult) @@ -12028,10 +11846,10 @@ dumpFunc(Archive *fout, FuncInfo *finfo) appendPQExpBuffer(q, "\n %s;\n", asPart->data); - appendPQExpBuffer(labelq, "%s %s", keyword, funcsig); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &finfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &finfo->dobj, + keyword, funcsig, + finfo->dobj.namespace->dobj.name); if (finfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId, @@ -12046,18 +11864,18 @@ dumpFunc(Archive *fout, FuncInfo *finfo) /* Dump Function Comments and Security Labels */ if (finfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, keyword, funcsig, finfo->dobj.namespace->dobj.name, finfo->rolname, finfo->dobj.catId, 0, finfo->dobj.dumpId); if (finfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, keyword, funcsig, finfo->dobj.namespace->dobj.name, finfo->rolname, finfo->dobj.catId, 0, finfo->dobj.dumpId); if (finfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, finfo->dobj.catId, finfo->dobj.dumpId, keyword, - funcsig, NULL, labelq->data, + funcsig, NULL, finfo->dobj.namespace->dobj.name, finfo->rolname, finfo->proacl, finfo->rproacl, finfo->initproacl, finfo->initrproacl); @@ -12067,7 +11885,6 @@ dumpFunc(Archive *fout, FuncInfo *finfo) destroyPQExpBuffer(query); destroyPQExpBuffer(q); destroyPQExpBuffer(delqry); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(asPart); free(funcsig); if (funcfullsig) @@ -12094,6 +11911,7 @@ dumpCast(Archive *fout, CastInfo *cast) PQExpBuffer defqry; PQExpBuffer delqry; PQExpBuffer labelq; + PQExpBuffer castargs; FuncInfo *funcInfo = NULL; char *sourceType; char *targetType; @@ -12111,15 +11929,10 @@ dumpCast(Archive *fout, CastInfo *cast) cast->castfunc); } - /* - * Make sure we are in proper schema (needed for getFormattedTypeName). - * Casts don't have a schema of their own, so use pg_catalog. - */ - selectSourceSchema(fout, "pg_catalog"); - defqry = createPQExpBuffer(); delqry = createPQExpBuffer(); labelq = createPQExpBuffer(); + castargs = createPQExpBuffer(); sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone); targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone); @@ -12143,9 +11956,8 @@ dumpCast(Archive *fout, CastInfo *cast) char *fsig = format_function_signature(fout, funcInfo, true); /* - * Always qualify the function name, in case it is not in - * pg_catalog schema (format_function_signature won't qualify - * it). + * Always qualify the function name (format_function_signature + * won't qualify it). */ appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s", fmtId(funcInfo->dobj.namespace->dobj.name), fsig); @@ -12167,13 +11979,17 @@ dumpCast(Archive *fout, CastInfo *cast) appendPQExpBuffer(labelq, "CAST (%s AS %s)", sourceType, targetType); + appendPQExpBuffer(castargs, "(%s AS %s)", + sourceType, targetType); + if (dopt->binary_upgrade) - binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data); + binary_upgrade_extension_member(defqry, &cast->dobj, + "CAST", castargs->data, NULL); if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId, labelq->data, - "pg_catalog", NULL, "", + NULL, NULL, "", false, "CAST", SECTION_PRE_DATA, defqry->data, delqry->data, NULL, NULL, 0, @@ -12181,8 +11997,8 @@ dumpCast(Archive *fout, CastInfo *cast) /* Dump Cast Comments */ if (cast->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, - "pg_catalog", "", + dumpComment(fout, "CAST", castargs->data, + NULL, "", cast->dobj.catId, 0, cast->dobj.dumpId); free(sourceType); @@ -12191,6 +12007,7 @@ dumpCast(Archive *fout, CastInfo *cast) destroyPQExpBuffer(defqry); destroyPQExpBuffer(delqry); destroyPQExpBuffer(labelq); + destroyPQExpBuffer(castargs); } /* @@ -12203,6 +12020,7 @@ dumpTransform(Archive *fout, TransformInfo *transform) PQExpBuffer defqry; PQExpBuffer delqry; PQExpBuffer labelq; + PQExpBuffer transformargs; FuncInfo *fromsqlFuncInfo = NULL; FuncInfo *tosqlFuncInfo = NULL; char *lanname; @@ -12228,12 +12046,10 @@ dumpTransform(Archive *fout, TransformInfo *transform) transform->trftosql); } - /* Make sure we are in proper schema (needed for getFormattedTypeName) */ - selectSourceSchema(fout, "pg_catalog"); - defqry = createPQExpBuffer(); delqry = createPQExpBuffer(); labelq = createPQExpBuffer(); + transformargs = createPQExpBuffer(); lanname = get_language_name(fout, transform->trflang); transformType = getFormattedTypeName(fout, transform->trftype, zeroAsNone); @@ -12254,8 +12070,8 @@ dumpTransform(Archive *fout, TransformInfo *transform) char *fsig = format_function_signature(fout, fromsqlFuncInfo, true); /* - * Always qualify the function name, in case it is not in - * pg_catalog schema (format_function_signature won't qualify it). + * Always qualify the function name (format_function_signature + * won't qualify it). */ appendPQExpBuffer(defqry, "FROM SQL WITH FUNCTION %s.%s", fmtId(fromsqlFuncInfo->dobj.namespace->dobj.name), fsig); @@ -12275,8 +12091,8 @@ dumpTransform(Archive *fout, TransformInfo *transform) char *fsig = format_function_signature(fout, tosqlFuncInfo, true); /* - * Always qualify the function name, in case it is not in - * pg_catalog schema (format_function_signature won't qualify it). + * Always qualify the function name (format_function_signature + * won't qualify it). */ appendPQExpBuffer(defqry, "TO SQL WITH FUNCTION %s.%s", fmtId(tosqlFuncInfo->dobj.namespace->dobj.name), fsig); @@ -12291,13 +12107,17 @@ dumpTransform(Archive *fout, TransformInfo *transform) appendPQExpBuffer(labelq, "TRANSFORM FOR %s LANGUAGE %s", transformType, lanname); + appendPQExpBuffer(transformargs, "FOR %s LANGUAGE %s", + transformType, lanname); + if (dopt->binary_upgrade) - binary_upgrade_extension_member(defqry, &transform->dobj, labelq->data); + binary_upgrade_extension_member(defqry, &transform->dobj, + "TRANSFORM", transformargs->data, NULL); if (transform->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, transform->dobj.catId, transform->dobj.dumpId, labelq->data, - "pg_catalog", NULL, "", + NULL, NULL, "", false, "TRANSFORM", SECTION_PRE_DATA, defqry->data, delqry->data, NULL, transform->dobj.dependencies, transform->dobj.nDeps, @@ -12305,8 +12125,8 @@ dumpTransform(Archive *fout, TransformInfo *transform) /* Dump Transform Comments */ if (transform->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, - "pg_catalog", "", + dumpComment(fout, "TRANSFORM", transformargs->data, + NULL, "", transform->dobj.catId, 0, transform->dobj.dumpId); free(lanname); @@ -12314,6 +12134,7 @@ dumpTransform(Archive *fout, TransformInfo *transform) destroyPQExpBuffer(defqry); destroyPQExpBuffer(delqry); destroyPQExpBuffer(labelq); + destroyPQExpBuffer(transformargs); } @@ -12328,7 +12149,6 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) PQExpBuffer query; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; PQExpBuffer oprid; PQExpBuffer details; PGresult *res; @@ -12369,21 +12189,17 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) query = createPQExpBuffer(); q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); oprid = createPQExpBuffer(); details = createPQExpBuffer(); - /* Make sure we are in proper schema so regoperator works correctly */ - selectSourceSchema(fout, oprinfo->dobj.namespace->dobj.name); - if (fout->remoteVersion >= 80300) { appendPQExpBuffer(query, "SELECT oprkind, " "oprcode::pg_catalog.regprocedure, " "oprleft::pg_catalog.regtype, " "oprright::pg_catalog.regtype, " - "oprcom::pg_catalog.regoperator, " - "oprnegate::pg_catalog.regoperator, " + "oprcom, " + "oprnegate, " "oprrest::pg_catalog.regprocedure, " "oprjoin::pg_catalog.regprocedure, " "oprcanmerge, oprcanhash " @@ -12397,8 +12213,8 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) "oprcode::pg_catalog.regprocedure, " "oprleft::pg_catalog.regtype, " "oprright::pg_catalog.regtype, " - "oprcom::pg_catalog.regoperator, " - "oprnegate::pg_catalog.regoperator, " + "oprcom, " + "oprnegate, " "oprrest::pg_catalog.regprocedure, " "oprjoin::pg_catalog.regprocedure, " "(oprlsortop != 0) AS oprcanmerge, " @@ -12464,14 +12280,14 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) else appendPQExpBufferStr(oprid, ", NONE)"); - oprref = convertOperatorReference(fout, oprcom); + oprref = getFormattedOperatorName(fout, oprcom); if (oprref) { appendPQExpBuffer(details, ",\n COMMUTATOR = %s", oprref); free(oprref); } - oprref = convertOperatorReference(fout, oprnegate); + oprref = getFormattedOperatorName(fout, oprnegate); if (oprref) { appendPQExpBuffer(details, ",\n NEGATOR = %s", oprref); @@ -12498,20 +12314,18 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) free(oprregproc); } - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ appendPQExpBuffer(delq, "DROP OPERATOR %s.%s;\n", fmtId(oprinfo->dobj.namespace->dobj.name), oprid->data); - appendPQExpBuffer(q, "CREATE OPERATOR %s (\n%s\n);\n", + appendPQExpBuffer(q, "CREATE OPERATOR %s.%s (\n%s\n);\n", + fmtId(oprinfo->dobj.namespace->dobj.name), oprinfo->dobj.name, details->data); - appendPQExpBuffer(labelq, "OPERATOR %s", oprid->data); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &oprinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &oprinfo->dobj, + "OPERATOR", oprid->data, + oprinfo->dobj.namespace->dobj.name); if (oprinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, oprinfo->dobj.catId, oprinfo->dobj.dumpId, @@ -12526,7 +12340,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) /* Dump Operator Comments */ if (oprinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "OPERATOR", oprid->data, oprinfo->dobj.namespace->dobj.name, oprinfo->rolname, oprinfo->dobj.catId, 0, oprinfo->dobj.dumpId); @@ -12535,7 +12349,6 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) destroyPQExpBuffer(query); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(oprid); destroyPQExpBuffer(details); } @@ -12577,49 +12390,39 @@ convertRegProcReference(Archive *fout, const char *proc) } /* - * Convert an operator cross-reference obtained from pg_operator + * getFormattedOperatorName - retrieve the operator name for the + * given operator OID (presented in string form). * - * Returns an allocated string of what to print, or NULL to print nothing. + * Returns an allocated string, or NULL if the given OID is invalid. * Caller is responsible for free'ing result string. * - * The input is a REGOPERATOR display; we have to strip the argument-types - * part, and add OPERATOR() decoration if the name is schema-qualified. + * What we produce has the format "OPERATOR(schema.oprname)". This is only + * useful in commands where the operator's argument types can be inferred from + * context. We always schema-qualify the name, though. The predecessor to + * this code tried to skip the schema qualification if possible, but that led + * to wrong results in corner cases, such as if an operator and its negator + * are in different schemas. */ static char * -convertOperatorReference(Archive *fout, const char *opr) +getFormattedOperatorName(Archive *fout, const char *oproid) { - char *name; - char *oname; - char *ptr; - bool inquote; - bool sawdot; + OprInfo *oprInfo; /* In all cases "0" means a null reference */ - if (strcmp(opr, "0") == 0) + if (strcmp(oproid, "0") == 0) return NULL; - name = pg_strdup(opr); - /* find non-double-quoted left paren, and check for non-quoted dot */ - inquote = false; - sawdot = false; - for (ptr = name; *ptr; ptr++) + oprInfo = findOprByOid(atooid(oproid)); + if (oprInfo == NULL) { - if (*ptr == '"') - inquote = !inquote; - else if (*ptr == '.' && !inquote) - sawdot = true; - else if (*ptr == '(' && !inquote) - { - *ptr = '\0'; - break; - } + write_msg(NULL, "WARNING: could not find operator with OID %s\n", + oproid); + return NULL; } - /* If not schema-qualified, don't need to add OPERATOR() */ - if (!sawdot) - return name; - oname = psprintf("OPERATOR(%s)", name); - free(name); - return oname; + + return psprintf("OPERATOR(%s.%s)", + fmtId(oprInfo->dobj.namespace->dobj.name), + oprInfo->dobj.name); } /* @@ -12658,7 +12461,6 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; char *qamname; /* Skip if not to be dumped */ @@ -12667,7 +12469,6 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); qamname = pg_strdup(fmtId(aminfo->dobj.name)); @@ -12681,10 +12482,9 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo) default: write_msg(NULL, "WARNING: invalid type \"%c\" of access method \"%s\"\n", aminfo->amtype, qamname); - pg_free(qamname); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qamname); return; } @@ -12693,11 +12493,9 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo) appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n", qamname); - appendPQExpBuffer(labelq, "ACCESS METHOD %s", - qamname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &aminfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &aminfo->dobj, + "ACCESS METHOD", qamname, NULL); if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId, @@ -12712,15 +12510,13 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo) /* Dump Access Method Comments */ if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "ACCESS METHOD", qamname, NULL, "", aminfo->dobj.catId, 0, aminfo->dobj.dumpId); - pg_free(qamname); - destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qamname); } /* @@ -12734,7 +12530,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) PQExpBuffer query; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; + PQExpBuffer nameusing; PGresult *res; int ntups; int i_opcintype; @@ -12779,10 +12575,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) query = createPQExpBuffer(); q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); - - /* Make sure we are in proper schema so regoperator works correctly */ - selectSourceSchema(fout, opcinfo->dobj.namespace->dobj.name); + nameusing = createPQExpBuffer(); /* Get additional fields from the pg_opclass row */ if (fout->remoteVersion >= 80300) @@ -12833,19 +12626,14 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) /* amname will still be needed after we PQclear res */ amname = pg_strdup(PQgetvalue(res, 0, i_amname)); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ appendPQExpBuffer(delq, "DROP OPERATOR CLASS %s", - fmtId(opcinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s", - fmtId(opcinfo->dobj.name)); + fmtQualifiedDumpable(opcinfo)); appendPQExpBuffer(delq, " USING %s;\n", fmtId(amname)); /* Build the fixed portion of the CREATE command */ appendPQExpBuffer(q, "CREATE OPERATOR CLASS %s\n ", - fmtId(opcinfo->dobj.name)); + fmtQualifiedDumpable(opcinfo)); if (strcmp(opcdefault, "t") == 0) appendPQExpBufferStr(q, "DEFAULT "); appendPQExpBuffer(q, "FOR TYPE %s USING %s", @@ -12854,8 +12642,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) if (strlen(opcfamilyname) > 0) { appendPQExpBufferStr(q, " FAMILY "); - if (strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0) - appendPQExpBuffer(q, "%s.", fmtId(opcfamilynsp)); + appendPQExpBuffer(q, "%s.", fmtId(opcfamilynsp)); appendPQExpBufferStr(q, fmtId(opcfamilyname)); } appendPQExpBufferStr(q, " AS\n "); @@ -12973,8 +12760,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) if (strlen(sortfamily) > 0) { appendPQExpBufferStr(q, " FOR ORDER BY "); - if (strcmp(sortfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0) - appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp)); + appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp)); appendPQExpBufferStr(q, fmtId(sortfamily)); } @@ -13068,13 +12854,14 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) appendPQExpBufferStr(q, ";\n"); - appendPQExpBuffer(labelq, "OPERATOR CLASS %s", - fmtId(opcinfo->dobj.name)); - appendPQExpBuffer(labelq, " USING %s", + appendPQExpBufferStr(nameusing, fmtId(opcinfo->dobj.name)); + appendPQExpBuffer(nameusing, " USING %s", fmtId(amname)); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &opcinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &opcinfo->dobj, + "OPERATOR CLASS", nameusing->data, + opcinfo->dobj.namespace->dobj.name); if (opcinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, opcinfo->dobj.catId, opcinfo->dobj.dumpId, @@ -13089,7 +12876,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) /* Dump Operator Class Comments */ if (opcinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "OPERATOR CLASS", nameusing->data, opcinfo->dobj.namespace->dobj.name, opcinfo->rolname, opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId); @@ -13099,7 +12886,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) destroyPQExpBuffer(query); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + destroyPQExpBuffer(nameusing); } /* @@ -13116,7 +12903,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) PQExpBuffer query; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; + PQExpBuffer nameusing; PGresult *res; PGresult *res_ops; PGresult *res_procs; @@ -13151,10 +12938,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) query = createPQExpBuffer(); q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); - - /* Make sure we are in proper schema so regoperator works correctly */ - selectSourceSchema(fout, opfinfo->dobj.namespace->dobj.name); + nameusing = createPQExpBuffer(); /* * Fetch only those opfamily members that are tied directly to the @@ -13246,19 +13030,14 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) /* amname will still be needed after we PQclear res */ amname = pg_strdup(PQgetvalue(res, 0, i_amname)); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ appendPQExpBuffer(delq, "DROP OPERATOR FAMILY %s", - fmtId(opfinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s", - fmtId(opfinfo->dobj.name)); + fmtQualifiedDumpable(opfinfo)); appendPQExpBuffer(delq, " USING %s;\n", fmtId(amname)); /* Build the fixed portion of the CREATE command */ appendPQExpBuffer(q, "CREATE OPERATOR FAMILY %s", - fmtId(opfinfo->dobj.name)); + fmtQualifiedDumpable(opfinfo)); appendPQExpBuffer(q, " USING %s;\n", fmtId(amname)); @@ -13268,7 +13047,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) if (PQntuples(res_ops) > 0 || PQntuples(res_procs) > 0) { appendPQExpBuffer(q, "ALTER OPERATOR FAMILY %s", - fmtId(opfinfo->dobj.name)); + fmtQualifiedDumpable(opfinfo)); appendPQExpBuffer(q, " USING %s ADD\n ", fmtId(amname)); @@ -13302,8 +13081,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) if (strlen(sortfamily) > 0) { appendPQExpBufferStr(q, " FOR ORDER BY "); - if (strcmp(sortfamilynsp, opfinfo->dobj.namespace->dobj.name) != 0) - appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp)); + appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp)); appendPQExpBufferStr(q, fmtId(sortfamily)); } @@ -13343,13 +13121,14 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) appendPQExpBufferStr(q, ";\n"); } - appendPQExpBuffer(labelq, "OPERATOR FAMILY %s", - fmtId(opfinfo->dobj.name)); - appendPQExpBuffer(labelq, " USING %s", + appendPQExpBufferStr(nameusing, fmtId(opfinfo->dobj.name)); + appendPQExpBuffer(nameusing, " USING %s", fmtId(amname)); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &opfinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &opfinfo->dobj, + "OPERATOR FAMILY", nameusing->data, + opfinfo->dobj.namespace->dobj.name); if (opfinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, opfinfo->dobj.catId, opfinfo->dobj.dumpId, @@ -13364,7 +13143,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) /* Dump Operator Family Comments */ if (opfinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "OPERATOR FAMILY", nameusing->data, opfinfo->dobj.namespace->dobj.name, opfinfo->rolname, opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId); @@ -13374,7 +13153,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) destroyPQExpBuffer(query); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + destroyPQExpBuffer(nameusing); } /* @@ -13388,7 +13167,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) PQExpBuffer query; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; + char *qcollname; PGresult *res; int i_collprovider; int i_collcollate; @@ -13404,10 +13183,8 @@ dumpCollation(Archive *fout, CollInfo *collinfo) query = createPQExpBuffer(); q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, collinfo->dobj.namespace->dobj.name); + qcollname = pg_strdup(fmtId(collinfo->dobj.name)); /* Get collation-specific details */ if (fout->remoteVersion >= 100000) @@ -13439,16 +13216,11 @@ dumpCollation(Archive *fout, CollInfo *collinfo) collcollate = PQgetvalue(res, 0, i_collcollate); collctype = PQgetvalue(res, 0, i_collctype); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP COLLATION %s", - fmtId(collinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s;\n", - fmtId(collinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP COLLATION %s;\n", + fmtQualifiedDumpable(collinfo)); appendPQExpBuffer(q, "CREATE COLLATION %s (", - fmtId(collinfo->dobj.name)); + fmtQualifiedDumpable(collinfo)); appendPQExpBufferStr(q, "provider = "); if (collprovider[0] == 'c') @@ -13496,10 +13268,10 @@ dumpCollation(Archive *fout, CollInfo *collinfo) appendPQExpBufferStr(q, ");\n"); - appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name)); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &collinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &collinfo->dobj, + "COLLATION", qcollname, + collinfo->dobj.namespace->dobj.name); if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId, @@ -13514,7 +13286,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) /* Dump Collation Comments */ if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "COLLATION", qcollname, collinfo->dobj.namespace->dobj.name, collinfo->rolname, collinfo->dobj.catId, 0, collinfo->dobj.dumpId); @@ -13523,7 +13295,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) destroyPQExpBuffer(query); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qcollname); } /* @@ -13537,7 +13309,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) PQExpBuffer query; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; + char *qconvname; PGresult *res; int i_conforencoding; int i_contoencoding; @@ -13555,10 +13327,8 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) query = createPQExpBuffer(); q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, convinfo->dobj.namespace->dobj.name); + qconvname = pg_strdup(fmtId(convinfo->dobj.name)); /* Get conversion-specific details */ appendPQExpBuffer(query, "SELECT " @@ -13581,27 +13351,22 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) conproc = PQgetvalue(res, 0, i_conproc); condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't'); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP CONVERSION %s", - fmtId(convinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s;\n", - fmtId(convinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP CONVERSION %s;\n", + fmtQualifiedDumpable(convinfo)); appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ", (condefault) ? "DEFAULT " : "", - fmtId(convinfo->dobj.name)); + fmtQualifiedDumpable(convinfo)); appendStringLiteralAH(q, conforencoding, fout); appendPQExpBufferStr(q, " TO "); appendStringLiteralAH(q, contoencoding, fout); /* regproc output is already sufficiently quoted */ appendPQExpBuffer(q, " FROM %s;\n", conproc); - appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name)); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &convinfo->dobj, + "CONVERSION", qconvname, + convinfo->dobj.namespace->dobj.name); if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId, @@ -13616,7 +13381,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) /* Dump Conversion Comments */ if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "CONVERSION", qconvname, convinfo->dobj.namespace->dobj.name, convinfo->rolname, convinfo->dobj.catId, 0, convinfo->dobj.dumpId); @@ -13625,7 +13390,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) destroyPQExpBuffer(query); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qconvname); } /* @@ -13679,7 +13444,6 @@ dumpAgg(Archive *fout, AggInfo *agginfo) PQExpBuffer query; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; PQExpBuffer details; char *aggsig; /* identity signature */ char *aggfullsig = NULL; /* full signature */ @@ -13739,12 +13503,8 @@ dumpAgg(Archive *fout, AggInfo *agginfo) query = createPQExpBuffer(); q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); details = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, agginfo->aggfn.dobj.namespace->dobj.name); - /* Get aggregate-specific details */ if (fout->remoteVersion >= 110000) { @@ -13754,7 +13514,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, " "aggfinalextra, aggmfinalextra, " "aggfinalmodify, aggmfinalmodify, " - "aggsortop::pg_catalog.regoperator, " + "aggsortop, " "aggkind, " "aggtransspace, agginitval, " "aggmtransspace, aggminitval, " @@ -13775,7 +13535,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, " "aggfinalextra, aggmfinalextra, " "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, " - "aggsortop::pg_catalog.regoperator, " + "aggsortop, " "aggkind, " "aggtransspace, agginitval, " "aggmtransspace, aggminitval, " @@ -13797,7 +13557,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) "aggmfinalfn, aggmtranstype::pg_catalog.regtype, " "aggfinalextra, aggmfinalextra, " "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, " - "aggsortop::pg_catalog.regoperator, " + "aggsortop, " "aggkind, " "aggtransspace, agginitval, " "aggmtransspace, aggminitval, " @@ -13819,7 +13579,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) "0 AS aggmtranstype, false AS aggfinalextra, " "false AS aggmfinalextra, " "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, " - "aggsortop::pg_catalog.regoperator, " + "aggsortop, " "'n' AS aggkind, " "0 AS aggtransspace, agginitval, " "0 AS aggmtransspace, NULL AS aggminitval, " @@ -13841,7 +13601,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) "0 AS aggmtranstype, false AS aggfinalextra, " "false AS aggmfinalextra, " "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, " - "aggsortop::pg_catalog.regoperator, " + "aggsortop, " "'n' AS aggkind, " "0 AS aggtransspace, agginitval, " "0 AS aggmtransspace, NULL AS aggminitval, " @@ -14061,7 +13821,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) } } - aggsortconvop = convertOperatorReference(fout, aggsortop); + aggsortconvop = getFormattedOperatorName(fout, aggsortop); if (aggsortconvop) { appendPQExpBuffer(details, ",\n SORTOP = %s", @@ -14083,20 +13843,18 @@ dumpAgg(Archive *fout, AggInfo *agginfo) agginfo->aggfn.dobj.name); } - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n", fmtId(agginfo->aggfn.dobj.namespace->dobj.name), aggsig); - appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n", + appendPQExpBuffer(q, "CREATE AGGREGATE %s.%s (\n%s\n);\n", + fmtId(agginfo->aggfn.dobj.namespace->dobj.name), aggfullsig ? aggfullsig : aggsig, details->data); - appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, labelq->data); + binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, + "AGGREGATE", aggsig, + agginfo->aggfn.dobj.namespace->dobj.name); if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, agginfo->aggfn.dobj.catId, @@ -14112,13 +13870,13 @@ dumpAgg(Archive *fout, AggInfo *agginfo) /* Dump Aggregate Comments */ if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "AGGREGATE", aggsig, agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname, agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId); if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "AGGREGATE", aggsig, agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname, agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId); @@ -14134,8 +13892,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId, - "FUNCTION", - aggsig, NULL, labelq->data, + "FUNCTION", aggsig, NULL, agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname, agginfo->aggfn.proacl, agginfo->aggfn.rproacl, @@ -14151,7 +13908,6 @@ dumpAgg(Archive *fout, AggInfo *agginfo) destroyPQExpBuffer(query); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(details); } @@ -14165,7 +13921,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; + char *qprsname; /* Skip if not to be dumped */ if (!prsinfo->dobj.dump || dopt->dataOnly) @@ -14173,13 +13929,11 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, prsinfo->dobj.namespace->dobj.name); + qprsname = pg_strdup(fmtId(prsinfo->dobj.name)); appendPQExpBuffer(q, "CREATE TEXT SEARCH PARSER %s (\n", - fmtId(prsinfo->dobj.name)); + fmtQualifiedDumpable(prsinfo)); appendPQExpBuffer(q, " START = %s,\n", convertTSFunction(fout, prsinfo->prsstart)); @@ -14193,19 +13947,13 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) appendPQExpBuffer(q, " LEXTYPES = %s );\n", convertTSFunction(fout, prsinfo->prslextype)); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP TEXT SEARCH PARSER %s", - fmtId(prsinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s;\n", - fmtId(prsinfo->dobj.name)); - - appendPQExpBuffer(labelq, "TEXT SEARCH PARSER %s", - fmtId(prsinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP TEXT SEARCH PARSER %s;\n", + fmtQualifiedDumpable(prsinfo)); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &prsinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &prsinfo->dobj, + "TEXT SEARCH PARSER", qprsname, + prsinfo->dobj.namespace->dobj.name); if (prsinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, prsinfo->dobj.catId, prsinfo->dobj.dumpId, @@ -14220,13 +13968,13 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) /* Dump Parser Comments */ if (prsinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TEXT SEARCH PARSER", qprsname, prsinfo->dobj.namespace->dobj.name, "", prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qprsname); } /* @@ -14239,8 +13987,8 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; PQExpBuffer query; + char *qdictname; PGresult *res; char *nspname; char *tmplname; @@ -14251,11 +13999,11 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); query = createPQExpBuffer(); + qdictname = pg_strdup(fmtId(dictinfo->dobj.name)); + /* Fetch name and namespace of the dictionary's template */ - selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT nspname, tmplname " "FROM pg_ts_template p, pg_namespace n " "WHERE p.oid = '%u' AND n.oid = tmplnamespace", @@ -14264,15 +14012,11 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) nspname = PQgetvalue(res, 0, 0); tmplname = PQgetvalue(res, 0, 1); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, dictinfo->dobj.namespace->dobj.name); - appendPQExpBuffer(q, "CREATE TEXT SEARCH DICTIONARY %s (\n", - fmtId(dictinfo->dobj.name)); + fmtQualifiedDumpable(dictinfo)); appendPQExpBufferStr(q, " TEMPLATE = "); - if (strcmp(nspname, dictinfo->dobj.namespace->dobj.name) != 0) - appendPQExpBuffer(q, "%s.", fmtId(nspname)); + appendPQExpBuffer(q, "%s.", fmtId(nspname)); appendPQExpBufferStr(q, fmtId(tmplname)); PQclear(res); @@ -14283,19 +14027,13 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) appendPQExpBufferStr(q, " );\n"); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP TEXT SEARCH DICTIONARY %s", - fmtId(dictinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s;\n", - fmtId(dictinfo->dobj.name)); - - appendPQExpBuffer(labelq, "TEXT SEARCH DICTIONARY %s", - fmtId(dictinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP TEXT SEARCH DICTIONARY %s;\n", + fmtQualifiedDumpable(dictinfo)); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &dictinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &dictinfo->dobj, + "TEXT SEARCH DICTIONARY", qdictname, + dictinfo->dobj.namespace->dobj.name); if (dictinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, dictinfo->dobj.catId, dictinfo->dobj.dumpId, @@ -14310,14 +14048,14 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) /* Dump Dictionary Comments */ if (dictinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TEXT SEARCH DICTIONARY", qdictname, dictinfo->dobj.namespace->dobj.name, dictinfo->rolname, dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qdictname); } /* @@ -14330,7 +14068,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; + char *qtmplname; /* Skip if not to be dumped */ if (!tmplinfo->dobj.dump || dopt->dataOnly) @@ -14338,13 +14076,11 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, tmplinfo->dobj.namespace->dobj.name); + qtmplname = pg_strdup(fmtId(tmplinfo->dobj.name)); appendPQExpBuffer(q, "CREATE TEXT SEARCH TEMPLATE %s (\n", - fmtId(tmplinfo->dobj.name)); + fmtQualifiedDumpable(tmplinfo)); if (tmplinfo->tmplinit != InvalidOid) appendPQExpBuffer(q, " INIT = %s,\n", @@ -14352,19 +14088,13 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) appendPQExpBuffer(q, " LEXIZE = %s );\n", convertTSFunction(fout, tmplinfo->tmpllexize)); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP TEXT SEARCH TEMPLATE %s", - fmtId(tmplinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s;\n", - fmtId(tmplinfo->dobj.name)); - - appendPQExpBuffer(labelq, "TEXT SEARCH TEMPLATE %s", - fmtId(tmplinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP TEXT SEARCH TEMPLATE %s;\n", + fmtQualifiedDumpable(tmplinfo)); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tmplinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tmplinfo->dobj, + "TEXT SEARCH TEMPLATE", qtmplname, + tmplinfo->dobj.namespace->dobj.name); if (tmplinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tmplinfo->dobj.catId, tmplinfo->dobj.dumpId, @@ -14379,13 +14109,13 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) /* Dump Template Comments */ if (tmplinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TEXT SEARCH TEMPLATE", qtmplname, tmplinfo->dobj.namespace->dobj.name, "", tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qtmplname); } /* @@ -14398,8 +14128,8 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; PQExpBuffer query; + char *qcfgname; PGresult *res; char *nspname; char *prsname; @@ -14414,11 +14144,11 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); query = createPQExpBuffer(); + qcfgname = pg_strdup(fmtId(cfginfo->dobj.name)); + /* Fetch name and namespace of the config's parser */ - selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT nspname, prsname " "FROM pg_ts_parser p, pg_namespace n " "WHERE p.oid = '%u' AND n.oid = prsnamespace", @@ -14427,15 +14157,10 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) nspname = PQgetvalue(res, 0, 0); prsname = PQgetvalue(res, 0, 1); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, cfginfo->dobj.namespace->dobj.name); - appendPQExpBuffer(q, "CREATE TEXT SEARCH CONFIGURATION %s (\n", - fmtId(cfginfo->dobj.name)); + fmtQualifiedDumpable(cfginfo)); - appendPQExpBufferStr(q, " PARSER = "); - if (strcmp(nspname, cfginfo->dobj.namespace->dobj.name) != 0) - appendPQExpBuffer(q, "%s.", fmtId(nspname)); + appendPQExpBuffer(q, " PARSER = %s.", fmtId(nspname)); appendPQExpBuffer(q, "%s );\n", fmtId(prsname)); PQclear(res); @@ -14469,7 +14194,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) if (i > 0) appendPQExpBufferStr(q, ";\n"); appendPQExpBuffer(q, "\nALTER TEXT SEARCH CONFIGURATION %s\n", - fmtId(cfginfo->dobj.name)); + fmtQualifiedDumpable(cfginfo)); /* tokenname needs quoting, dictname does NOT */ appendPQExpBuffer(q, " ADD MAPPING FOR %s WITH %s", fmtId(tokenname), dictname); @@ -14483,19 +14208,13 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) PQclear(res); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "DROP TEXT SEARCH CONFIGURATION %s", - fmtId(cfginfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, ".%s;\n", - fmtId(cfginfo->dobj.name)); - - appendPQExpBuffer(labelq, "TEXT SEARCH CONFIGURATION %s", - fmtId(cfginfo->dobj.name)); + appendPQExpBuffer(delq, "DROP TEXT SEARCH CONFIGURATION %s;\n", + fmtQualifiedDumpable(cfginfo)); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &cfginfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &cfginfo->dobj, + "TEXT SEARCH CONFIGURATION", qcfgname, + cfginfo->dobj.namespace->dobj.name); if (cfginfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, cfginfo->dobj.catId, cfginfo->dobj.dumpId, @@ -14510,14 +14229,14 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) /* Dump Configuration Comments */ if (cfginfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "TEXT SEARCH CONFIGURATION", qcfgname, cfginfo->dobj.namespace->dobj.name, cfginfo->rolname, cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qcfgname); } /* @@ -14530,7 +14249,6 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; char *qfdwname; /* Skip if not to be dumped */ @@ -14539,7 +14257,6 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); qfdwname = pg_strdup(fmtId(fdwinfo->dobj.name)); @@ -14560,11 +14277,10 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) appendPQExpBuffer(delq, "DROP FOREIGN DATA WRAPPER %s;\n", qfdwname); - appendPQExpBuffer(labelq, "FOREIGN DATA WRAPPER %s", - qfdwname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &fdwinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &fdwinfo->dobj, + "FOREIGN DATA WRAPPER", qfdwname, + NULL); if (fdwinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId, @@ -14579,15 +14295,14 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) /* Dump Foreign Data Wrapper Comments */ if (fdwinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "FOREIGN DATA WRAPPER", qfdwname, NULL, fdwinfo->rolname, fdwinfo->dobj.catId, 0, fdwinfo->dobj.dumpId); /* Handle the ACL */ if (fdwinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId, - "FOREIGN DATA WRAPPER", - qfdwname, NULL, labelq->data, + "FOREIGN DATA WRAPPER", qfdwname, NULL, NULL, fdwinfo->rolname, fdwinfo->fdwacl, fdwinfo->rfdwacl, fdwinfo->initfdwacl, fdwinfo->initrfdwacl); @@ -14596,7 +14311,6 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); } /* @@ -14609,7 +14323,6 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; PQExpBuffer query; PGresult *res; char *qsrvname; @@ -14621,13 +14334,11 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); query = createPQExpBuffer(); qsrvname = pg_strdup(fmtId(srvinfo->dobj.name)); /* look up the foreign-data wrapper */ - selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT fdwname " "FROM pg_foreign_data_wrapper w " "WHERE w.oid = '%u'", @@ -14658,10 +14369,9 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) appendPQExpBuffer(delq, "DROP SERVER %s;\n", qsrvname); - appendPQExpBuffer(labelq, "SERVER %s", qsrvname); - if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &srvinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &srvinfo->dobj, + "SERVER", qsrvname, NULL); if (srvinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId, @@ -14676,15 +14386,14 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) /* Dump Foreign Server Comments */ if (srvinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "SERVER", qsrvname, NULL, srvinfo->rolname, srvinfo->dobj.catId, 0, srvinfo->dobj.dumpId); /* Handle the ACL */ if (srvinfo->dobj.dump & DUMP_COMPONENT_ACL) dumpACL(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId, - "FOREIGN SERVER", - qsrvname, NULL, labelq->data, + "FOREIGN SERVER", qsrvname, NULL, NULL, srvinfo->rolname, srvinfo->srvacl, srvinfo->rsrvacl, srvinfo->initsrvacl, srvinfo->initrsrvacl); @@ -14700,7 +14409,6 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); } @@ -14740,8 +14448,6 @@ dumpUserMappings(Archive *fout, * OPTIONS clause. A possible alternative is to skip such mappings * altogether, but it's not clear that that's an improvement. */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT usename, " "array_to_string(ARRAY(" @@ -14889,8 +14595,7 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo) * FOREIGN DATA WRAPPER, SERVER, or LARGE OBJECT. * 'name' is the formatted name of the object. Must be quoted etc. already. * 'subname' is the formatted name of the sub-object, if any. Must be quoted. - * 'tag' is the tag for the archive entry (should be the same tag as would be - * used for comments etc; for example "TABLE foo"). + * (Currently we assume that subname is only provided for table columns.) * 'nspname' is the namespace the object is in (NULL if none). * 'owner' is the owner, NULL if there is no owner (for languages). * 'acls' contains the ACL string of the object from the appropriate system @@ -14912,7 +14617,7 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo) static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, - const char *tag, const char *nspname, const char *owner, + const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls) { @@ -14940,7 +14645,8 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, if (strlen(initacls) != 0 || strlen(initracls) != 0) { appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n"); - if (!buildACLCommands(name, subname, type, initacls, initracls, owner, + if (!buildACLCommands(name, subname, nspname, type, + initacls, initracls, owner, "", fout->remoteVersion, sql)) exit_horribly(NULL, "could not parse initial GRANT ACL list (%s) or initial REVOKE ACL list (%s) for object \"%s\" (%s)\n", @@ -14948,21 +14654,32 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n"); } - if (!buildACLCommands(name, subname, type, acls, racls, owner, + if (!buildACLCommands(name, subname, nspname, type, + acls, racls, owner, "", fout->remoteVersion, sql)) exit_horribly(NULL, "could not parse GRANT ACL list (%s) or REVOKE ACL list (%s) for object \"%s\" (%s)\n", acls, racls, name, type); if (sql->len > 0) + { + PQExpBuffer tag = createPQExpBuffer(); + + if (subname) + appendPQExpBuffer(tag, "COLUMN %s.%s", name, subname); + else + appendPQExpBuffer(tag, "%s %s", type, name); + ArchiveEntry(fout, nilCatalogId, createDumpId(), - tag, nspname, + tag->data, nspname, NULL, owner ? owner : "", false, "ACL", SECTION_NONE, sql->data, "", NULL, &(objDumpId), 1, NULL, NULL); + destroyPQExpBuffer(tag); + } destroyPQExpBuffer(sql); } @@ -14971,8 +14688,8 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, * dumpSecLabel * * This routine is used to dump any security labels associated with the - * object handed to this routine. The routine takes a constant character - * string for the target part of the security-label command, plus + * object handed to this routine. The routine takes the object type + * and object name (ready to print, except for schema decoration), plus * the namespace and owner of the object (for labeling the ArchiveEntry), * plus catalog ID and subid which are the lookup key for pg_seclabel, * plus the dump ID for the object (for setting a dependency). @@ -14986,7 +14703,7 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, * calling ArchiveEntry() for the specified object. */ static void -dumpSecLabel(Archive *fout, const char *target, +dumpSecLabel(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId) { @@ -15001,7 +14718,7 @@ dumpSecLabel(Archive *fout, const char *target, return; /* Security labels are schema not data ... except blob labels are data */ - if (strncmp(target, "LARGE OBJECT ", 13) != 0) + if (strcmp(type, "LARGE OBJECT") != 0) { if (dopt->dataOnly) return; @@ -15027,21 +14744,29 @@ dumpSecLabel(Archive *fout, const char *target, continue; appendPQExpBuffer(query, - "SECURITY LABEL FOR %s ON %s IS ", - fmtId(labels[i].provider), target); + "SECURITY LABEL FOR %s ON %s ", + fmtId(labels[i].provider), type); + if (namespace && *namespace) + appendPQExpBuffer(query, "%s.", fmtId(namespace)); + appendPQExpBuffer(query, "%s IS ", name); appendStringLiteralAH(query, labels[i].label, fout); appendPQExpBufferStr(query, ";\n"); } if (query->len > 0) { + PQExpBuffer tag = createPQExpBuffer(); + + appendPQExpBuffer(tag, "%s %s", type, name); ArchiveEntry(fout, nilCatalogId, createDumpId(), - target, namespace, NULL, owner, + tag->data, namespace, NULL, owner, false, "SECURITY LABEL", SECTION_NONE, query->data, "", NULL, &(dumpId), 1, NULL, NULL); + destroyPQExpBuffer(tag); } + destroyPQExpBuffer(query); } @@ -15093,13 +14818,14 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename) if (objsubid == 0) { appendPQExpBuffer(target, "%s %s", reltypename, - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); } else { colname = getAttrName(objsubid, tbinfo); - /* first fmtId result must be consumed before calling it again */ - appendPQExpBuffer(target, "COLUMN %s", fmtId(tbinfo->dobj.name)); + /* first fmtXXX result must be consumed before calling again */ + appendPQExpBuffer(target, "COLUMN %s", + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(target, ".%s", fmtId(colname)); } appendPQExpBuffer(query, "SECURITY LABEL FOR %s ON %s IS ", @@ -15297,14 +15023,12 @@ dumpTable(Archive *fout, TableInfo *tbinfo) { const char *objtype = (tbinfo->relkind == RELKIND_SEQUENCE) ? "SEQUENCE" : "TABLE"; - char *acltag = psprintf("%s %s", objtype, namecopy); dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, - objtype, namecopy, NULL, acltag, + objtype, namecopy, NULL, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tbinfo->relacl, tbinfo->rrelacl, tbinfo->initrelacl, tbinfo->initrrelacl); - free(acltag); } /* @@ -15386,17 +15110,14 @@ dumpTable(Archive *fout, TableInfo *tbinfo) char *initattacl = PQgetvalue(res, i, 3); char *initrattacl = PQgetvalue(res, i, 4); char *attnamecopy; - char *acltag; attnamecopy = pg_strdup(fmtId(attname)); - acltag = psprintf("COLUMN %s.%s", namecopy, attnamecopy); /* Column's GRANT type is always TABLE */ - dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, "TABLE", - namecopy, attnamecopy, acltag, + dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, + "TABLE", namecopy, attnamecopy, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, attacl, rattacl, initattacl, initrattacl); free(attnamecopy); - free(acltag); } PQclear(res); destroyPQExpBuffer(query); @@ -15488,12 +15209,8 @@ createDummyViewAsClause(Archive *fout, TableInfo *tbinfo) coll = findCollationByOid(tbinfo->attcollation[j]); if (coll) - { - /* always schema-qualify, don't try to be smart */ - appendPQExpBuffer(result, " COLLATE %s.", - fmtId(coll->dobj.namespace->dobj.name)); - appendPQExpBufferStr(result, fmtId(coll->dobj.name)); - } + appendPQExpBuffer(result, " COLLATE %s", + fmtQualifiedDumpable(coll)); } appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j])); @@ -15512,7 +15229,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); + char *qrelname; + char *qualrelname; int numParents; TableInfo **parents; int actual_atts; /* number of attrs in this CREATE statement */ @@ -15523,8 +15241,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) int j, k; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); + qrelname = pg_strdup(fmtId(tbinfo->dobj.name)); + qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo)); if (dopt->binary_upgrade) binary_upgrade_set_type_oids_by_rel_oid(fout, q, @@ -15541,20 +15259,14 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) reltypename = "VIEW"; - /* - * DROP must be fully qualified in case same name appears in - * pg_catalog - */ - appendPQExpBuffer(delq, "DROP VIEW %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP VIEW %s;\n", qualrelname); if (dopt->binary_upgrade) binary_upgrade_set_pg_class_oids(fout, q, tbinfo->dobj.catId.oid, false); - appendPQExpBuffer(q, "CREATE VIEW %s", fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(q, "CREATE VIEW %s", qualrelname); + if (tbinfo->dummy_view) result = createDummyViewAsClause(fout, tbinfo); else @@ -15573,9 +15285,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) if (tbinfo->checkoption != NULL && !tbinfo->dummy_view) appendPQExpBuffer(q, "\n WITH %s CHECK OPTION", tbinfo->checkoption); appendPQExpBufferStr(q, ";\n"); - - appendPQExpBuffer(labelq, "VIEW %s", - fmtId(tbinfo->dobj.name)); } else { @@ -15627,17 +15336,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) numParents = tbinfo->numParents; parents = tbinfo->parents; - /* - * DROP must be fully qualified in case same name appears in - * pg_catalog - */ - appendPQExpBuffer(delq, "DROP %s %s.", reltypename, - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - fmtId(tbinfo->dobj.name)); - - appendPQExpBuffer(labelq, "%s %s", reltypename, - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP %s %s;\n", reltypename, qualrelname); if (dopt->binary_upgrade) binary_upgrade_set_pg_class_oids(fout, q, @@ -15647,7 +15346,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ? "UNLOGGED " : "", reltypename, - fmtId(tbinfo->dobj.name)); + qualrelname); /* * Attach to type, if reloftype; except in case of a binary upgrade, @@ -15673,11 +15372,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) exit_horribly(NULL, "invalid number of parents %d for table \"%s\"\n", tbinfo->numParents, tbinfo->dobj.name); - appendPQExpBuffer(q, " PARTITION OF "); - if (parentRel->dobj.namespace != tbinfo->dobj.namespace) - appendPQExpBuffer(q, "%s.", - fmtId(parentRel->dobj.namespace->dobj.name)); - appendPQExpBufferStr(q, fmtId(parentRel->dobj.name)); + appendPQExpBuffer(q, " PARTITION OF %s", + fmtQualifiedDumpable(parentRel)); } if (tbinfo->relkind != RELKIND_MATVIEW) @@ -15762,12 +15458,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) coll = findCollationByOid(tbinfo->attcollation[j]); if (coll) - { - /* always schema-qualify, don't try to be smart */ - appendPQExpBuffer(q, " COLLATE %s.", - fmtId(coll->dobj.namespace->dobj.name)); - appendPQExpBufferStr(q, fmtId(coll->dobj.name)); - } + appendPQExpBuffer(q, " COLLATE %s", + fmtQualifiedDumpable(coll)); } if (has_default) @@ -15831,10 +15523,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) if (k > 0) appendPQExpBufferStr(q, ", "); - if (parentRel->dobj.namespace != tbinfo->dobj.namespace) - appendPQExpBuffer(q, "%s.", - fmtId(parentRel->dobj.namespace->dobj.name)); - appendPQExpBufferStr(q, fmtId(parentRel->dobj.name)); + appendPQExpBufferStr(q, fmtQualifiedDumpable(parentRel)); } appendPQExpBufferChar(q, ')'); } @@ -15926,16 +15615,16 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) tbinfo->attalign[j]); appendStringLiteralAH(q, tbinfo->attnames[j], fout); appendPQExpBufferStr(q, "\n AND attrelid = "); - appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); + appendStringLiteralAH(q, qualrelname, fout); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n"); if (tbinfo->relkind == RELKIND_RELATION || tbinfo->relkind == RELKIND_PARTITIONED_TABLE) appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); else appendPQExpBuffer(q, "ALTER FOREIGN TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, "DROP COLUMN %s;\n", fmtId(tbinfo->attnames[j])); } @@ -15947,7 +15636,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) "WHERE attname = "); appendStringLiteralAH(q, tbinfo->attnames[j], fout); appendPQExpBufferStr(q, "\n AND attrelid = "); - appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); + appendStringLiteralAH(q, qualrelname, fout); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n"); } } @@ -15961,7 +15650,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inherited constraint.\n"); appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, " ADD CONSTRAINT %s ", fmtId(constr->dobj.name)); appendPQExpBuffer(q, "%s;\n", constr->condef); @@ -15970,7 +15659,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) "WHERE contype = 'c' AND conname = "); appendStringLiteralAH(q, constr->dobj.name, fout); appendPQExpBufferStr(q, "\n AND conrelid = "); - appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); + appendStringLiteralAH(q, qualrelname, fout); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n"); } @@ -15980,34 +15669,24 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) for (k = 0; k < numParents; k++) { TableInfo *parentRel = parents[k]; - PQExpBuffer parentname = createPQExpBuffer(); - - /* Schema-qualify the parent table, if necessary */ - if (parentRel->dobj.namespace != tbinfo->dobj.namespace) - appendPQExpBuffer(parentname, "%s.", - fmtId(parentRel->dobj.namespace->dobj.name)); - - appendPQExpBuffer(parentname, "%s", - fmtId(parentRel->dobj.name)); /* In the partitioning case, we alter the parent */ if (tbinfo->ispartition) appendPQExpBuffer(q, "ALTER TABLE ONLY %s ATTACH PARTITION ", - parentname->data); + fmtQualifiedDumpable(parentRel)); else appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT ", - fmtId(tbinfo->dobj.name)); + qualrelname); /* Partition needs specifying the bounds */ if (tbinfo->ispartition) appendPQExpBuffer(q, "%s %s;\n", - fmtId(tbinfo->dobj.name), + qualrelname, tbinfo->partbound); else - appendPQExpBuffer(q, "%s;\n", parentname->data); - - destroyPQExpBuffer(parentname); + appendPQExpBuffer(q, "%s;\n", + fmtQualifiedDumpable(parentRel)); } } @@ -16015,7 +15694,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) { appendPQExpBufferStr(q, "\n-- For binary upgrade, set up typed tables this way.\n"); appendPQExpBuffer(q, "ALTER TABLE ONLY %s OF %s;\n", - fmtId(tbinfo->dobj.name), + qualrelname, tbinfo->reloftype); } } @@ -16036,7 +15715,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) "SET relfrozenxid = '%u', relminmxid = '%u'\n" "WHERE oid = ", tbinfo->frozenxid, tbinfo->minmxid); - appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); + appendStringLiteralAH(q, qualrelname, fout); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n"); if (tbinfo->toast_oid) @@ -16068,7 +15747,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) appendPQExpBufferStr(q, "UPDATE pg_catalog.pg_class\n" "SET relispopulated = 't'\n" "WHERE oid = "); - appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); + appendStringLiteralAH(q, qualrelname, fout); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n"); } @@ -16091,7 +15770,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) tbinfo->notnull[j] && !tbinfo->inhNotNull[j]) { appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, "ALTER COLUMN %s SET NOT NULL;\n", fmtId(tbinfo->attnames[j])); } @@ -16104,7 +15783,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) if (tbinfo->attstattarget[j] >= 0) { appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, "ALTER COLUMN %s ", fmtId(tbinfo->attnames[j])); appendPQExpBuffer(q, "SET STATISTICS %d;\n", @@ -16141,7 +15820,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) if (storage != NULL) { appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, "ALTER COLUMN %s ", fmtId(tbinfo->attnames[j])); appendPQExpBuffer(q, "SET STORAGE %s;\n", @@ -16155,7 +15834,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) if (tbinfo->attoptions[j] && tbinfo->attoptions[j][0] != '\0') { appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, "ALTER COLUMN %s ", fmtId(tbinfo->attnames[j])); appendPQExpBuffer(q, "SET (%s);\n", @@ -16170,7 +15849,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) tbinfo->attfdwoptions[j][0] != '\0') { appendPQExpBuffer(q, "ALTER FOREIGN TABLE %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, "ALTER COLUMN %s ", fmtId(tbinfo->attnames[j])); appendPQExpBuffer(q, "OPTIONS (\n %s\n);\n", @@ -16194,25 +15873,27 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) else if (tbinfo->relreplident == REPLICA_IDENTITY_NOTHING) { appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY NOTHING;\n", - fmtId(tbinfo->dobj.name)); + qualrelname); } else if (tbinfo->relreplident == REPLICA_IDENTITY_FULL) { appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY FULL;\n", - fmtId(tbinfo->dobj.name)); + qualrelname); } } if (tbinfo->relkind == RELKIND_FOREIGN_TABLE && tbinfo->hasoids) appendPQExpBuffer(q, "\nALTER TABLE ONLY %s SET WITH OIDS;\n", - fmtId(tbinfo->dobj.name)); + qualrelname); if (tbinfo->forcerowsec) appendPQExpBuffer(q, "\nALTER TABLE ONLY %s FORCE ROW LEVEL SECURITY;\n", - fmtId(tbinfo->dobj.name)); + qualrelname); if (dopt->binary_upgrade) - binary_upgrade_extension_member(q, &tbinfo->dobj, labelq->data); + binary_upgrade_extension_member(q, &tbinfo->dobj, + reltypename, qrelname, + tbinfo->dobj.namespace->dobj.name); if (tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, @@ -16251,7 +15932,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qrelname); + free(qualrelname); } /* @@ -16265,6 +15947,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo) int adnum = adinfo->adnum; PQExpBuffer q; PQExpBuffer delq; + char *qualrelname; char *tag; /* Skip if table definition not to be dumped */ @@ -16278,19 +15961,16 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); + qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo)); + appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", - fmtId(tbinfo->dobj.name)); + qualrelname); appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n", fmtId(tbinfo->attnames[adnum - 1]), adinfo->adef_expr); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ - appendPQExpBuffer(delq, "ALTER TABLE %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s ", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delq, "ALTER TABLE %s ", + qualrelname); appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n", fmtId(tbinfo->attnames[adnum - 1])); @@ -16310,6 +15990,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo) free(tag); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); + free(qualrelname); } /* @@ -16358,17 +16039,15 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) bool is_constraint = (indxinfo->indexconstraint != 0); PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; + char *qindxname; if (dopt->dataOnly) return; q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); - appendPQExpBuffer(labelq, "INDEX %s", - fmtId(indxinfo->dobj.name)); + qindxname = pg_strdup(fmtId(indxinfo->dobj.name)); /* * If there's an associated constraint, don't dump the index per se, but @@ -16390,28 +16069,24 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) if (indxinfo->indisclustered) { appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); + /* index name is not qualified in this syntax */ appendPQExpBuffer(q, " ON %s;\n", - fmtId(indxinfo->dobj.name)); + qindxname); } /* If the index defines identity, we need to record that. */ if (indxinfo->indisreplident) { appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY USING", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); + /* index name is not qualified in this syntax */ appendPQExpBuffer(q, " INDEX %s;\n", - fmtId(indxinfo->dobj.name)); + qindxname); } - /* - * DROP must be fully qualified in case same name appears in - * pg_catalog - */ - appendPQExpBuffer(delq, "DROP INDEX %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - fmtId(indxinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP INDEX %s;\n", + fmtQualifiedDumpable(indxinfo)); if (indxinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, indxinfo->dobj.catId, indxinfo->dobj.dumpId, @@ -16427,7 +16102,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) /* Dump Index Comments */ if (indxinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "INDEX", qindxname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, indxinfo->dobj.catId, 0, @@ -16436,7 +16111,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); + free(qindxname); } /* @@ -16454,13 +16129,9 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo) PQExpBuffer q = createPQExpBuffer(); appendPQExpBuffer(q, "\nALTER INDEX %s ", - fmtQualifiedId(fout->remoteVersion, - attachinfo->parentIdx->dobj.namespace->dobj.name, - attachinfo->parentIdx->dobj.name)); + fmtQualifiedDumpable(attachinfo->parentIdx)); appendPQExpBuffer(q, "ATTACH PARTITION %s;\n", - fmtQualifiedId(fout->remoteVersion, - attachinfo->partitionIdx->dobj.namespace->dobj.name, - attachinfo->partitionIdx->dobj.name)); + fmtQualifiedDumpable(attachinfo->partitionIdx)); ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId, attachinfo->dobj.name, @@ -16485,8 +16156,8 @@ dumpStatisticsExt(Archive *fout, StatsExtInfo *statsextinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer q; PQExpBuffer delq; - PQExpBuffer labelq; PQExpBuffer query; + char *qstatsextname; PGresult *res; char *stxdef; @@ -16496,11 +16167,9 @@ dumpStatisticsExt(Archive *fout, StatsExtInfo *statsextinfo) q = createPQExpBuffer(); delq = createPQExpBuffer(); - labelq = createPQExpBuffer(); query = createPQExpBuffer(); - /* Make sure we are in proper schema so references are qualified */ - selectSourceSchema(fout, statsextinfo->dobj.namespace->dobj.name); + qstatsextname = pg_strdup(fmtId(statsextinfo->dobj.name)); appendPQExpBuffer(query, "SELECT " "pg_catalog.pg_get_statisticsobjdef('%u'::pg_catalog.oid)", @@ -16510,16 +16179,11 @@ dumpStatisticsExt(Archive *fout, StatsExtInfo *statsextinfo) stxdef = PQgetvalue(res, 0, 0); - appendPQExpBuffer(labelq, "STATISTICS %s", - fmtId(statsextinfo->dobj.name)); - /* Result of pg_get_statisticsobjdef is complete except for semicolon */ appendPQExpBuffer(q, "%s;\n", stxdef); - appendPQExpBuffer(delq, "DROP STATISTICS %s.", - fmtId(statsextinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s;\n", - fmtId(statsextinfo->dobj.name)); + appendPQExpBuffer(delq, "DROP STATISTICS %s;\n", + fmtQualifiedDumpable(statsextinfo)); if (statsextinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, statsextinfo->dobj.catId, @@ -16535,7 +16199,7 @@ dumpStatisticsExt(Archive *fout, StatsExtInfo *statsextinfo) /* Dump Statistics Comments */ if (statsextinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "STATISTICS", qstatsextname, statsextinfo->dobj.namespace->dobj.name, statsextinfo->rolname, statsextinfo->dobj.catId, 0, @@ -16544,8 +16208,8 @@ dumpStatisticsExt(Archive *fout, StatsExtInfo *statsextinfo) PQclear(res); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); - destroyPQExpBuffer(labelq); destroyPQExpBuffer(query); + free(qstatsextname); } /* @@ -16587,7 +16251,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) indxinfo->dobj.catId.oid, true); appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(q, " ADD CONSTRAINT %s ", fmtId(coninfo->dobj.name)); @@ -16637,19 +16301,14 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) if (indxinfo->indisclustered) { appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); + /* index name is not qualified in this syntax */ appendPQExpBuffer(q, " ON %s;\n", fmtId(indxinfo->dobj.name)); } - /* - * DROP must be fully qualified in case same name appears in - * pg_catalog - */ - appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s ", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delq, "ALTER TABLE ONLY %s ", + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n", fmtId(coninfo->dobj.name)); @@ -16673,19 +16332,13 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) * current table data is not processed */ appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n", fmtId(coninfo->dobj.name), coninfo->condef); - /* - * DROP must be fully qualified in case same name appears in - * pg_catalog - */ - appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s ", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delq, "ALTER TABLE ONLY %s ", + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n", fmtId(coninfo->dobj.name)); @@ -16711,19 +16364,13 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) { /* not ONLY since we want it to propagate to children */ appendPQExpBuffer(q, "ALTER TABLE %s\n", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n", fmtId(coninfo->dobj.name), coninfo->condef); - /* - * DROP must be fully qualified in case same name appears in - * pg_catalog - */ - appendPQExpBuffer(delq, "ALTER TABLE %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s ", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delq, "ALTER TABLE %s ", + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n", fmtId(coninfo->dobj.name)); @@ -16750,19 +16397,13 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) if (coninfo->separate) { appendPQExpBuffer(q, "ALTER DOMAIN %s\n", - fmtId(tyinfo->dobj.name)); + fmtQualifiedDumpable(tyinfo)); appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n", fmtId(coninfo->dobj.name), coninfo->condef); - /* - * DROP must be fully qualified in case same name appears in - * pg_catalog - */ - appendPQExpBuffer(delq, "ALTER DOMAIN %s.", - fmtId(tyinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delq, "%s ", - fmtId(tyinfo->dobj.name)); + appendPQExpBuffer(delq, "ALTER DOMAIN %s ", + fmtQualifiedDumpable(tyinfo)); appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n", fmtId(coninfo->dobj.name)); @@ -16807,21 +16448,23 @@ static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo) { TableInfo *tbinfo = coninfo->contable; - PQExpBuffer labelq = createPQExpBuffer(); + PQExpBuffer conprefix = createPQExpBuffer(); + char *qtabname; - appendPQExpBuffer(labelq, "CONSTRAINT %s ", + qtabname = pg_strdup(fmtId(tbinfo->dobj.name)); + + appendPQExpBuffer(conprefix, "CONSTRAINT %s ON", fmtId(coninfo->dobj.name)); - appendPQExpBuffer(labelq, "ON %s", - fmtId(tbinfo->dobj.name)); if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, conprefix->data, qtabname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, coninfo->dobj.catId, 0, coninfo->separate ? coninfo->dobj.dumpId : tbinfo->dobj.dumpId); - destroyPQExpBuffer(labelq); + destroyPQExpBuffer(conprefix); + free(qtabname); } /* @@ -16874,52 +16517,42 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) bufx[32]; PQExpBuffer query = createPQExpBuffer(); PQExpBuffer delqry = createPQExpBuffer(); - PQExpBuffer labelq = createPQExpBuffer(); + char *qseqname; + + qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); if (fout->remoteVersion >= 100000) { - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - appendPQExpBuffer(query, "SELECT format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " "seqcache, seqcycle " - "FROM pg_class c " - "JOIN pg_sequence s ON (s.seqrelid = c.oid) " - "WHERE c.oid = '%u'::oid", + "FROM pg_catalog.pg_sequence " + "WHERE seqrelid = '%u'::oid", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 80400) { /* - * Before PostgreSQL 10, sequence metadata is in the sequence itself, - * so switch to the sequence's schema instead of pg_catalog. + * Before PostgreSQL 10, sequence metadata is in the sequence itself. * * Note: it might seem that 'bigint' potentially needs to be * schema-qualified, but actually that's a keyword. */ - - /* Make sure we are in proper schema */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - appendPQExpBuffer(query, "SELECT 'bigint' AS sequence_type, " "start_value, increment_by, max_value, min_value, " "cache_value, is_cycled FROM %s", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); } else { - /* Make sure we are in proper schema */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - appendPQExpBuffer(query, "SELECT 'bigint' AS sequence_type, " "0 AS start_value, increment_by, max_value, min_value, " "cache_value, is_cycled FROM %s", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -16978,14 +16611,12 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) maxv = NULL; /* - * DROP must be fully qualified in case same name appears in pg_catalog + * Identity sequences are not to be dropped separately. */ if (!tbinfo->is_identity_sequence) { - appendPQExpBuffer(delqry, "DROP SEQUENCE %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delqry, "%s;\n", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delqry, "DROP SEQUENCE %s;\n", + fmtQualifiedDumpable(tbinfo)); } resetPQExpBuffer(query); @@ -17004,7 +16635,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) appendPQExpBuffer(query, "ALTER TABLE %s ", - fmtId(owning_tab->dobj.name)); + fmtQualifiedDumpable(owning_tab)); appendPQExpBuffer(query, "ALTER COLUMN %s ADD GENERATED ", fmtId(owning_tab->attnames[tbinfo->owning_col - 1])); @@ -17013,13 +16644,13 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) else if (owning_tab->attidentity[tbinfo->owning_col - 1] == ATTRIBUTE_IDENTITY_BY_DEFAULT) appendPQExpBuffer(query, "BY DEFAULT"); appendPQExpBuffer(query, " AS IDENTITY (\n SEQUENCE NAME %s\n", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); } else { appendPQExpBuffer(query, "CREATE SEQUENCE %s\n", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); if (strcmp(seqtype, "bigint") != 0) appendPQExpBuffer(query, " AS %s\n", seqtype); @@ -17049,13 +16680,12 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) else appendPQExpBufferStr(query, ";\n"); - appendPQExpBuffer(labelq, "SEQUENCE %s", fmtId(tbinfo->dobj.name)); - /* binary_upgrade: no need to clear TOAST table oid */ if (dopt->binary_upgrade) binary_upgrade_extension_member(query, &tbinfo->dobj, - labelq->data); + "SEQUENCE", qseqname, + tbinfo->dobj.namespace->dobj.name); if (tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, @@ -17092,9 +16722,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) { resetPQExpBuffer(query); appendPQExpBuffer(query, "ALTER SEQUENCE %s", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); appendPQExpBuffer(query, " OWNED BY %s", - fmtId(owning_tab->dobj.name)); + fmtQualifiedDumpable(owning_tab)); appendPQExpBuffer(query, ".%s;\n", fmtId(owning_tab->attnames[tbinfo->owning_col - 1])); @@ -17113,12 +16743,12 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) /* Dump Sequence Comments and Security Labels */ if (tbinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "SEQUENCE", qseqname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId); if (tbinfo->dobj.dump & DUMP_COMPONENT_SECLABEL) - dumpSecLabel(fout, labelq->data, + dumpSecLabel(fout, "SEQUENCE", qseqname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId); @@ -17126,7 +16756,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) destroyPQExpBuffer(query); destroyPQExpBuffer(delqry); - destroyPQExpBuffer(labelq); + free(qseqname); } /* @@ -17142,12 +16772,9 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo) bool called; PQExpBuffer query = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - appendPQExpBuffer(query, "SELECT last_value, is_called FROM %s", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -17165,7 +16792,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo) resetPQExpBuffer(query); appendPQExpBufferStr(query, "SELECT pg_catalog.setval("); - appendStringLiteralAH(query, fmtId(tbinfo->dobj.name), fout); + appendStringLiteralAH(query, fmtQualifiedDumpable(tbinfo), fout); appendPQExpBuffer(query, ", %s, %s);\n", last, (called ? "true" : "false")); @@ -17196,7 +16823,8 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) TableInfo *tbinfo = tginfo->tgtable; PQExpBuffer query; PQExpBuffer delqry; - PQExpBuffer labelq; + PQExpBuffer trigprefix; + char *qtabname; char *tgargs; size_t lentgargs; const char *p; @@ -17212,17 +16840,14 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) query = createPQExpBuffer(); delqry = createPQExpBuffer(); - labelq = createPQExpBuffer(); + trigprefix = createPQExpBuffer(); + + qtabname = pg_strdup(fmtId(tbinfo->dobj.name)); - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ appendPQExpBuffer(delqry, "DROP TRIGGER %s ", fmtId(tginfo->dobj.name)); - appendPQExpBuffer(delqry, "ON %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delqry, "%s;\n", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delqry, "ON %s;\n", + fmtQualifiedDumpable(tbinfo)); if (tginfo->tgdef) { @@ -17286,7 +16911,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) findx++; } appendPQExpBuffer(query, " ON %s\n", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); if (tginfo->tgisconstraint) { @@ -17344,7 +16969,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) if (tginfo->tgenabled != 't' && tginfo->tgenabled != 'O') { appendPQExpBuffer(query, "\nALTER TABLE %s ", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); switch (tginfo->tgenabled) { case 'D': @@ -17365,10 +16990,8 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) fmtId(tginfo->dobj.name)); } - appendPQExpBuffer(labelq, "TRIGGER %s ", + appendPQExpBuffer(trigprefix, "TRIGGER %s ON", fmtId(tginfo->dobj.name)); - appendPQExpBuffer(labelq, "ON %s", - fmtId(tbinfo->dobj.name)); tag = psprintf("%s %s", tbinfo->dobj.name, tginfo->dobj.name); @@ -17384,14 +17007,15 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) NULL, NULL); if (tginfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, trigprefix->data, qtabname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tginfo->dobj.catId, 0, tginfo->dobj.dumpId); free(tag); destroyPQExpBuffer(query); destroyPQExpBuffer(delqry); - destroyPQExpBuffer(labelq); + destroyPQExpBuffer(trigprefix); + free(qtabname); } /* @@ -17404,7 +17028,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) DumpOptions *dopt = fout->dopt; PQExpBuffer query; PQExpBuffer delqry; - PQExpBuffer labelq; + char *qevtname; /* Skip if not to be dumped */ if (!evtinfo->dobj.dump || dopt->dataOnly) @@ -17412,10 +17036,11 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) query = createPQExpBuffer(); delqry = createPQExpBuffer(); - labelq = createPQExpBuffer(); + + qevtname = pg_strdup(fmtId(evtinfo->dobj.name)); appendPQExpBufferStr(query, "CREATE EVENT TRIGGER "); - appendPQExpBufferStr(query, fmtId(evtinfo->dobj.name)); + appendPQExpBufferStr(query, qevtname); appendPQExpBufferStr(query, " ON "); appendPQExpBufferStr(query, fmtId(evtinfo->evtevent)); @@ -17433,7 +17058,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) if (evtinfo->evtenabled != 'O') { appendPQExpBuffer(query, "\nALTER EVENT TRIGGER %s ", - fmtId(evtinfo->dobj.name)); + qevtname); switch (evtinfo->evtenabled) { case 'D': @@ -17453,10 +17078,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) } appendPQExpBuffer(delqry, "DROP EVENT TRIGGER %s;\n", - fmtId(evtinfo->dobj.name)); - - appendPQExpBuffer(labelq, "EVENT TRIGGER %s", - fmtId(evtinfo->dobj.name)); + qevtname); if (evtinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) ArchiveEntry(fout, evtinfo->dobj.catId, evtinfo->dobj.dumpId, @@ -17468,13 +17090,13 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) NULL, NULL); if (evtinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, "EVENT TRIGGER", qevtname, NULL, evtinfo->evtowner, evtinfo->dobj.catId, 0, evtinfo->dobj.dumpId); destroyPQExpBuffer(query); destroyPQExpBuffer(delqry); - destroyPQExpBuffer(labelq); + free(qevtname); } /* @@ -17490,7 +17112,8 @@ dumpRule(Archive *fout, RuleInfo *rinfo) PQExpBuffer query; PQExpBuffer cmd; PQExpBuffer delcmd; - PQExpBuffer labelq; + PQExpBuffer ruleprefix; + char *qtabname; PGresult *res; char *tag; @@ -17511,15 +17134,12 @@ dumpRule(Archive *fout, RuleInfo *rinfo) */ is_view = (rinfo->ev_type == '1' && rinfo->is_instead); - /* - * Make sure we are in proper schema. - */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - query = createPQExpBuffer(); cmd = createPQExpBuffer(); delcmd = createPQExpBuffer(); - labelq = createPQExpBuffer(); + ruleprefix = createPQExpBuffer(); + + qtabname = pg_strdup(fmtId(tbinfo->dobj.name)); if (is_view) { @@ -17530,7 +17150,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo) * Otherwise this should look largely like the regular view dump code. */ appendPQExpBuffer(cmd, "CREATE OR REPLACE VIEW %s", - fmtId(tbinfo->dobj.name)); + fmtQualifiedDumpable(tbinfo)); if (nonemptyReloptions(tbinfo->reloptions)) { appendPQExpBufferStr(cmd, " WITH ("); @@ -17572,7 +17192,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo) */ if (rinfo->ev_enabled != 'O') { - appendPQExpBuffer(cmd, "ALTER TABLE %s ", fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(cmd, "ALTER TABLE %s ", fmtQualifiedDumpable(tbinfo)); switch (rinfo->ev_enabled) { case 'A': @@ -17590,9 +17210,6 @@ dumpRule(Archive *fout, RuleInfo *rinfo) } } - /* - * DROP must be fully qualified in case same name appears in pg_catalog - */ if (is_view) { /* @@ -17602,9 +17219,8 @@ dumpRule(Archive *fout, RuleInfo *rinfo) */ PQExpBuffer result; - appendPQExpBuffer(delcmd, "CREATE OR REPLACE VIEW %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBufferStr(delcmd, fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delcmd, "CREATE OR REPLACE VIEW %s", + fmtQualifiedDumpable(tbinfo)); result = createDummyViewAsClause(fout, tbinfo); appendPQExpBuffer(delcmd, " AS\n%s;\n", result->data); destroyPQExpBuffer(result); @@ -17613,16 +17229,12 @@ dumpRule(Archive *fout, RuleInfo *rinfo) { appendPQExpBuffer(delcmd, "DROP RULE %s ", fmtId(rinfo->dobj.name)); - appendPQExpBuffer(delcmd, "ON %s.", - fmtId(tbinfo->dobj.namespace->dobj.name)); - appendPQExpBuffer(delcmd, "%s;\n", - fmtId(tbinfo->dobj.name)); + appendPQExpBuffer(delcmd, "ON %s;\n", + fmtQualifiedDumpable(tbinfo)); } - appendPQExpBuffer(labelq, "RULE %s", + appendPQExpBuffer(ruleprefix, "RULE %s ON", fmtId(rinfo->dobj.name)); - appendPQExpBuffer(labelq, " ON %s", - fmtId(tbinfo->dobj.name)); tag = psprintf("%s %s", tbinfo->dobj.name, rinfo->dobj.name); @@ -17639,7 +17251,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo) /* Dump rule comments */ if (rinfo->dobj.dump & DUMP_COMPONENT_COMMENT) - dumpComment(fout, labelq->data, + dumpComment(fout, ruleprefix->data, qtabname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, rinfo->dobj.catId, 0, rinfo->dobj.dumpId); @@ -17648,7 +17260,8 @@ dumpRule(Archive *fout, RuleInfo *rinfo) destroyPQExpBuffer(query); destroyPQExpBuffer(cmd); destroyPQExpBuffer(delcmd); - destroyPQExpBuffer(labelq); + destroyPQExpBuffer(ruleprefix); + free(qtabname); } /* @@ -17680,9 +17293,6 @@ getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], if (numExtensions == 0) return; - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - query = createPQExpBuffer(); /* refclassid constraint is redundant but may speed the search */ @@ -17882,9 +17492,6 @@ processExtensionTables(Archive *fout, ExtensionInfo extinfo[], * recreated after the data has been loaded. */ - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - query = createPQExpBuffer(); printfPQExpBuffer(query, @@ -17952,9 +17559,6 @@ getDependencies(Archive *fout) if (g_verbose) write_msg(NULL, "reading dependency data\n"); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, "pg_catalog"); - query = createPQExpBuffer(); /* @@ -18284,45 +17888,13 @@ findDumpableDependencies(ArchiveHandle *AH, DumpableObject *dobj, /* - * selectSourceSchema - make the specified schema the active search path - * in the source database. - * - * NB: pg_catalog is explicitly searched after the specified schema; - * so user names are only qualified if they are cross-schema references, - * and system names are only qualified if they conflict with a user name - * in the current schema. - * - * Whenever the selected schema is not pg_catalog, be careful to qualify - * references to system catalogs and types in our emitted commands! - * - * This function is called only from selectSourceSchemaOnAH and - * selectSourceSchema. - */ -static void -selectSourceSchema(Archive *fout, const char *schemaName) -{ - PQExpBuffer query; - - /* This is checked by the callers already */ - Assert(schemaName != NULL && *schemaName != '\0'); - - query = createPQExpBuffer(); - appendPQExpBuffer(query, "SET search_path = %s", - fmtId(schemaName)); - if (strcmp(schemaName, "pg_catalog") != 0) - appendPQExpBufferStr(query, ", pg_catalog"); - - ExecuteSqlStatement(fout, query->data); - - destroyPQExpBuffer(query); -} - -/* * getFormattedTypeName - retrieve a nicely-formatted type name for the - * given type name. + * given type OID. + * + * This does not guarantee to schema-qualify the output, so it should not + * be used to create the target object name for CREATE or ALTER commands. * - * NB: the result may depend on the currently-selected search_path; this is - * why we don't try to cache the names. + * TODO: there might be some value in caching the results. */ static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 40ee5d1d8b7..fbb18b7adee 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -42,9 +42,10 @@ static void dumpUserConfig(PGconn *conn, const char *username); static void dumpDatabases(PGconn *conn); static void dumpTimestamp(const char *msg); static int runPgDump(const char *dbname, const char *create_opts); -static void buildShSecLabels(PGconn *conn, const char *catalog_name, - uint32 objectId, PQExpBuffer buffer, - const char *target, const char *objname); +static void buildShSecLabels(PGconn *conn, + const char *catalog_name, Oid objectId, + const char *objtype, const char *objname, + PQExpBuffer buffer); static PGconn *connectDatabase(const char *dbname, const char *connstr, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error); static char *constructConnStr(const char **keywords, const char **values); @@ -928,7 +929,8 @@ dumpRoles(PGconn *conn) if (!no_security_labels && server_version >= 90200) buildShSecLabels(conn, "pg_authid", auth_oid, - buf, "ROLE", rolename); + "ROLE", rolename, + buf); fprintf(OPF, "%s", buf->data); } @@ -1191,7 +1193,7 @@ dumpTablespaces(PGconn *conn) for (i = 0; i < PQntuples(res); i++) { PQExpBuffer buf = createPQExpBuffer(); - uint32 spcoid = atooid(PQgetvalue(res, i, 0)); + Oid spcoid = atooid(PQgetvalue(res, i, 0)); char *spcname = PQgetvalue(res, i, 1); char *spcowner = PQgetvalue(res, i, 2); char *spclocation = PQgetvalue(res, i, 3); @@ -1216,11 +1218,12 @@ dumpTablespaces(PGconn *conn) fspcname, spcoptions); if (!skip_acls && - !buildACLCommands(fspcname, NULL, "TABLESPACE", spcacl, rspcacl, + !buildACLCommands(fspcname, NULL, NULL, "TABLESPACE", + spcacl, rspcacl, spcowner, "", server_version, buf)) { fprintf(stderr, _("%s: could not parse ACL list (%s) for tablespace \"%s\"\n"), - progname, spcacl, fspcname); + progname, spcacl, spcname); PQfinish(conn); exit_nicely(1); } @@ -1234,7 +1237,8 @@ dumpTablespaces(PGconn *conn) if (!no_security_labels && server_version >= 90200) buildShSecLabels(conn, "pg_tablespace", spcoid, - buf, "TABLESPACE", fspcname); + "TABLESPACE", spcname, + buf); fprintf(OPF, "%s", buf->data); @@ -1481,19 +1485,23 @@ runPgDump(const char *dbname, const char *create_opts) * * Build SECURITY LABEL command(s) for a shared object * - * The caller has to provide object type and identifier to select security - * labels from pg_seclabels system view. + * The caller has to provide object type and identity in two separate formats: + * catalog_name (e.g., "pg_database") and object OID, as well as + * type name (e.g., "DATABASE") and object name (not pre-quoted). + * + * The command(s) are appended to "buffer". */ static void -buildShSecLabels(PGconn *conn, const char *catalog_name, uint32 objectId, - PQExpBuffer buffer, const char *target, const char *objname) +buildShSecLabels(PGconn *conn, const char *catalog_name, Oid objectId, + const char *objtype, const char *objname, + PQExpBuffer buffer) { PQExpBuffer sql = createPQExpBuffer(); PGresult *res; buildShSecLabelQuery(conn, catalog_name, objectId, sql); res = executeQuery(conn, sql->data); - emitShSecLabels(conn, res, buffer, target, objname); + emitShSecLabels(conn, res, buffer, objtype, objname); PQclear(res); destroyPQExpBuffer(sql); diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index ac9cfa04c1f..6f74e158052 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -460,7 +460,7 @@ my %tests = ( 'ALTER COLLATION test0 OWNER TO' => { all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', - regexp => qr/^ALTER COLLATION test0 OWNER TO .*;/m, + regexp => qr/^ALTER COLLATION public.test0 OWNER TO .*;/m, collation => 1, like => { binary_upgrade => 1, @@ -604,7 +604,7 @@ my %tests = ( FUNCTION 1 (int4, int4) btint4cmp(int4,int4), FUNCTION 2 (int4, int4) btint4sortsupport(internal);', regexp => qr/^ - \QALTER OPERATOR FAMILY op_family USING btree ADD\E\n\s+ + \QALTER OPERATOR FAMILY dump_test.op_family USING btree ADD\E\n\s+ \QOPERATOR 1 <(bigint,integer) ,\E\n\s+ \QOPERATOR 2 <=(bigint,integer) ,\E\n\s+ \QOPERATOR 3 =(bigint,integer) ,\E\n\s+ @@ -809,7 +809,7 @@ my %tests = ( 'ALTER SEQUENCE test_table_col1_seq' => { all_runs => 1, regexp => qr/^ - \QALTER SEQUENCE test_table_col1_seq OWNED BY test_table.col1;\E + \QALTER SEQUENCE dump_test.test_table_col1_seq OWNED BY dump_test.test_table.col1;\E /xm, like => { binary_upgrade => 1, @@ -842,7 +842,7 @@ my %tests = ( 'ALTER SEQUENCE test_third_table_col1_seq' => { all_runs => 1, regexp => qr/^ - \QALTER SEQUENCE test_third_table_col1_seq OWNED BY test_third_table.col1;\E + \QALTER SEQUENCE dump_test_second_schema.test_third_table_col1_seq OWNED BY dump_test_second_schema.test_third_table.col1;\E /xm, like => { binary_upgrade => 1, @@ -876,7 +876,7 @@ my %tests = ( all_runs => 1, catch_all => 'ALTER TABLE ... commands', regexp => qr/^ - \QALTER TABLE ONLY test_table\E \n^\s+ + \QALTER TABLE ONLY dump_test.test_table\E \n^\s+ \QADD CONSTRAINT test_table_pkey PRIMARY KEY (col1);\E /xm, like => { @@ -911,7 +911,7 @@ my %tests = ( create_sql => 'ALTER TABLE dump_test.test_table ALTER COLUMN col1 SET STATISTICS 90;', regexp => qr/^ - \QALTER TABLE ONLY test_table ALTER COLUMN col1 SET STATISTICS 90;\E\n + \QALTER TABLE ONLY dump_test.test_table ALTER COLUMN col1 SET STATISTICS 90;\E\n /xm, like => { binary_upgrade => 1, @@ -945,7 +945,7 @@ my %tests = ( create_sql => 'ALTER TABLE dump_test.test_table ALTER COLUMN col2 SET STORAGE EXTERNAL;', regexp => qr/^ - \QALTER TABLE ONLY test_table ALTER COLUMN col2 SET STORAGE EXTERNAL;\E\n + \QALTER TABLE ONLY dump_test.test_table ALTER COLUMN col2 SET STORAGE EXTERNAL;\E\n /xm, like => { binary_upgrade => 1, @@ -979,7 +979,7 @@ my %tests = ( create_sql => 'ALTER TABLE dump_test.test_table ALTER COLUMN col3 SET STORAGE MAIN;', regexp => qr/^ - \QALTER TABLE ONLY test_table ALTER COLUMN col3 SET STORAGE MAIN;\E\n + \QALTER TABLE ONLY dump_test.test_table ALTER COLUMN col3 SET STORAGE MAIN;\E\n /xm, like => { binary_upgrade => 1, @@ -1013,7 +1013,7 @@ my %tests = ( create_sql => 'ALTER TABLE dump_test.test_table ALTER COLUMN col4 SET (n_distinct = 10);', regexp => qr/^ - \QALTER TABLE ONLY test_table ALTER COLUMN col4 SET (n_distinct=10);\E\n + \QALTER TABLE ONLY dump_test.test_table ALTER COLUMN col4 SET (n_distinct=10);\E\n /xm, like => { binary_upgrade => 1, @@ -1044,7 +1044,7 @@ my %tests = ( => { all_runs => 1, regexp => qr/^ - \QALTER TABLE ONLY dump_test.measurement ATTACH PARTITION measurement_y2006m2 \E + \QALTER TABLE ONLY dump_test.measurement ATTACH PARTITION dump_test_second_schema.measurement_y2006m2 \E \QFOR VALUES FROM ('2006-02-01') TO ('2006-03-01');\E\n /xm, like => { binary_upgrade => 1, }, @@ -1081,7 +1081,7 @@ my %tests = ( create_sql => 'ALTER TABLE dump_test.test_table CLUSTER ON test_table_pkey', regexp => qr/^ - \QALTER TABLE test_table CLUSTER ON test_table_pkey;\E\n + \QALTER TABLE dump_test.test_table CLUSTER ON test_table_pkey;\E\n /xm, like => { binary_upgrade => 1, @@ -1112,10 +1112,10 @@ my %tests = ( all_runs => 1, regexp => qr/^ \QSET SESSION AUTHORIZATION 'test_superuser';\E\n\n - \QALTER TABLE test_table DISABLE TRIGGER ALL;\E\n\n - \QCOPY test_table (col1, col2, col3, col4) FROM stdin;\E + \QALTER TABLE dump_test.test_table DISABLE TRIGGER ALL;\E\n\n + \QCOPY dump_test.test_table (col1, col2, col3, col4) FROM stdin;\E \n(?:\d\t\\N\t\\N\t\\N\n){9}\\\.\n\n\n - \QALTER TABLE test_table ENABLE TRIGGER ALL;\E/xm, + \QALTER TABLE dump_test.test_table ENABLE TRIGGER ALL;\E/xm, like => { data_only => 1, }, unlike => { binary_upgrade => 1, @@ -1147,7 +1147,7 @@ my %tests = ( all_runs => 1, catch_all => 'ALTER TABLE ... commands', regexp => qr/^ - \QALTER FOREIGN TABLE foreign_table ALTER COLUMN c1 OPTIONS (\E\n + \QALTER FOREIGN TABLE dump_test.foreign_table ALTER COLUMN c1 OPTIONS (\E\n \s+\Qcolumn_name 'col1'\E\n \Q);\E\n /xm, @@ -1178,7 +1178,7 @@ my %tests = ( 'ALTER TABLE test_table OWNER TO' => { all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', - regexp => qr/^ALTER TABLE test_table OWNER TO .*;/m, + regexp => qr/^ALTER TABLE dump_test.test_table OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1207,7 +1207,7 @@ my %tests = ( create_order => 23, create_sql => 'ALTER TABLE dump_test.test_table ENABLE ROW LEVEL SECURITY;', - regexp => qr/^ALTER TABLE test_table ENABLE ROW LEVEL SECURITY;/m, + regexp => qr/^ALTER TABLE dump_test.test_table ENABLE ROW LEVEL SECURITY;/m, like => { binary_upgrade => 1, clean => 1, @@ -1235,7 +1235,7 @@ my %tests = ( 'ALTER TABLE test_second_table OWNER TO' => { all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', - regexp => qr/^ALTER TABLE test_second_table OWNER TO .*;/m, + regexp => qr/^ALTER TABLE dump_test.test_second_table OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1261,7 +1261,7 @@ my %tests = ( 'ALTER TABLE test_third_table OWNER TO' => { all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', - regexp => qr/^ALTER TABLE test_third_table OWNER TO .*;/m, + regexp => qr/^ALTER TABLE dump_test_second_schema.test_third_table OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1287,7 +1287,7 @@ my %tests = ( 'ALTER TABLE measurement OWNER TO' => { all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', - regexp => qr/^ALTER TABLE measurement OWNER TO .*;/m, + regexp => qr/^ALTER TABLE dump_test.measurement OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1313,7 +1313,7 @@ my %tests = ( 'ALTER TABLE measurement_y2006m2 OWNER TO' => { all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', - regexp => qr/^ALTER TABLE measurement_y2006m2 OWNER TO .*;/m, + regexp => qr/^ALTER TABLE dump_test_second_schema.measurement_y2006m2 OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1339,7 +1339,7 @@ my %tests = ( 'ALTER FOREIGN TABLE foreign_table OWNER TO' => { all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', - regexp => qr/^ALTER FOREIGN TABLE foreign_table OWNER TO .*;/m, + regexp => qr/^ALTER FOREIGN TABLE dump_test.foreign_table OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1366,7 +1366,7 @@ my %tests = ( all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', regexp => - qr/^ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 OWNER TO .*;/m, + qr/^ALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1 OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1393,7 +1393,7 @@ my %tests = ( all_runs => 1, catch_all => 'ALTER ... OWNER commands (except post-data objects)', regexp => - qr/^ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 OWNER TO .*;/m, + qr/^ALTER TEXT SEARCH DICTIONARY dump_test.alt_ts_dict1 OWNER TO .*;/m, like => { binary_upgrade => 1, clean => 1, @@ -1580,7 +1580,7 @@ qr/^ALTER (?!EVENT TRIGGER|LARGE OBJECT|STATISTICS|PUBLICATION|SUBSCRIPTION)(.*) create_order => 36, create_sql => 'COMMENT ON TABLE dump_test.test_table IS \'comment on table\';', - regexp => qr/^COMMENT ON TABLE test_table IS 'comment on table';/m, + regexp => qr/^COMMENT ON TABLE dump_test.test_table IS 'comment on table';/m, like => { binary_upgrade => 1, clean => 1, @@ -1613,7 +1613,7 @@ qr/^ALTER (?!EVENT TRIGGER|LARGE OBJECT|STATISTICS|PUBLICATION|SUBSCRIPTION)(.*) create_sql => 'COMMENT ON COLUMN dump_test.test_table.col1 IS \'comment on column\';', regexp => qr/^ - \QCOMMENT ON COLUMN test_table.col1 IS 'comment on column';\E + \QCOMMENT ON COLUMN dump_test.test_table.col1 IS 'comment on column';\E /xm, like => { binary_upgrade => 1, @@ -1647,7 +1647,7 @@ qr/^ALTER (?!EVENT TRIGGER|LARGE OBJECT|STATISTICS|PUBLICATION|SUBSCRIPTION)(.*) create_sql => 'COMMENT ON COLUMN dump_test.composite.f1 IS \'comment on column of type\';', regexp => qr/^ - \QCOMMENT ON COLUMN composite.f1 IS 'comment on column of type';\E + \QCOMMENT ON COLUMN dump_test.composite.f1 IS 'comment on column of type';\E /xm, like => { binary_upgrade => 1, @@ -1681,7 +1681,7 @@ qr/^ALTER (?!EVENT TRIGGER|LARGE OBJECT|STATISTICS|PUBLICATION|SUBSCRIPTION)(.*) create_sql => 'COMMENT ON COLUMN dump_test.test_second_table.col1 IS \'comment on column col1\';', regexp => qr/^ - \QCOMMENT ON COLUMN test_second_table.col1 IS 'comment on column col1';\E + \QCOMMENT ON COLUMN dump_test.test_second_table.col1 IS 'comment on column col1';\E /xm, like => { binary_upgrade => 1, @@ -1715,7 +1715,7 @@ qr/^ALTER (?!EVENT TRIGGER|LARGE OBJECT|STATISTICS|PUBLICATION|SUBSCRIPTION)(.*) create_sql => 'COMMENT ON COLUMN dump_test.test_second_table.col2 IS \'comment on column col2\';', regexp => qr/^ - \QCOMMENT ON COLUMN test_second_table.col2 IS 'comment on column col2';\E + \QCOMMENT ON COLUMN dump_test.test_second_table.col2 IS 'comment on column col2';\E /xm, like => { binary_upgrade => 1, @@ -1749,7 +1749,7 @@ qr/^ALTER (?!EVENT TRIGGER|LARGE OBJECT|STATISTICS|PUBLICATION|SUBSCRIPTION)(.*) create_sql => 'COMMENT ON CONVERSION dump_test.test_conversion IS \'comment on test conversion\';', regexp => -qr/^COMMENT ON CONVERSION test_conversion IS 'comment on test conversion';/m, +qr/^COMMENT ON CONVERSION dump_test.test_conversion IS 'comment on test conversion';/m, like => { binary_upgrade => 1, clean => 1, @@ -1782,7 +1782,7 @@ qr/^COMMENT ON CONVERSION test_conversion IS 'comment on test conversion';/m, create_sql => 'COMMENT ON COLLATION test0 IS \'comment on test0 collation\';', regexp => - qr/^COMMENT ON COLLATION test0 IS 'comment on test0 collation';/m, + qr/^COMMENT ON COLLATION public.test0 IS 'comment on test0 collation';/m, collation => 1, like => { binary_upgrade => 1, @@ -1928,7 +1928,7 @@ qr/^COMMENT ON CONVERSION test_conversion IS 'comment on test conversion';/m, 'COMMENT ON TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1 IS \'comment on text search configuration\';', regexp => -qr/^COMMENT ON TEXT SEARCH CONFIGURATION alt_ts_conf1 IS 'comment on text search configuration';/m, +qr/^COMMENT ON TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1 IS 'comment on text search configuration';/m, like => { binary_upgrade => 1, clean => 1, @@ -1962,7 +1962,7 @@ qr/^COMMENT ON TEXT SEARCH CONFIGURATION alt_ts_conf1 IS 'comment on text search 'COMMENT ON TEXT SEARCH DICTIONARY dump_test.alt_ts_dict1 IS \'comment on text search dictionary\';', regexp => -qr/^COMMENT ON TEXT SEARCH DICTIONARY alt_ts_dict1 IS 'comment on text search dictionary';/m, +qr/^COMMENT ON TEXT SEARCH DICTIONARY dump_test.alt_ts_dict1 IS 'comment on text search dictionary';/m, like => { binary_upgrade => 1, clean => 1, @@ -1995,7 +1995,7 @@ qr/^COMMENT ON TEXT SEARCH DICTIONARY alt_ts_dict1 IS 'comment on text search di create_sql => 'COMMENT ON TEXT SEARCH PARSER dump_test.alt_ts_prs1 IS \'comment on text search parser\';', regexp => -qr/^COMMENT ON TEXT SEARCH PARSER alt_ts_prs1 IS 'comment on text search parser';/m, +qr/^COMMENT ON TEXT SEARCH PARSER dump_test.alt_ts_prs1 IS 'comment on text search parser';/m, like => { binary_upgrade => 1, clean => 1, @@ -2028,7 +2028,7 @@ qr/^COMMENT ON TEXT SEARCH PARSER alt_ts_prs1 IS 'comment on text search parser' create_sql => 'COMMENT ON TEXT SEARCH TEMPLATE dump_test.alt_ts_temp1 IS \'comment on text search template\';', regexp => -qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search template';/m, +qr/^COMMENT ON TEXT SEARCH TEMPLATE dump_test.alt_ts_temp1 IS 'comment on text search template';/m, like => { binary_upgrade => 1, clean => 1, @@ -2060,7 +2060,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_order => 68, create_sql => 'COMMENT ON TYPE dump_test.planets IS \'comment on enum type\';', - regexp => qr/^COMMENT ON TYPE planets IS 'comment on enum type';/m, + regexp => qr/^COMMENT ON TYPE dump_test.planets IS 'comment on enum type';/m, like => { binary_upgrade => 1, clean => 1, @@ -2092,7 +2092,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_order => 69, create_sql => 'COMMENT ON TYPE dump_test.textrange IS \'comment on range type\';', - regexp => qr/^COMMENT ON TYPE textrange IS 'comment on range type';/m, + regexp => qr/^COMMENT ON TYPE dump_test.textrange IS 'comment on range type';/m, like => { binary_upgrade => 1, clean => 1, @@ -2124,7 +2124,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_order => 70, create_sql => 'COMMENT ON TYPE dump_test.int42 IS \'comment on regular type\';', - regexp => qr/^COMMENT ON TYPE int42 IS 'comment on regular type';/m, + regexp => qr/^COMMENT ON TYPE dump_test.int42 IS 'comment on regular type';/m, like => { binary_upgrade => 1, clean => 1, @@ -2157,7 +2157,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_sql => 'COMMENT ON TYPE dump_test.undefined IS \'comment on undefined type\';', regexp => - qr/^COMMENT ON TYPE undefined IS 'comment on undefined type';/m, + qr/^COMMENT ON TYPE dump_test.undefined IS 'comment on undefined type';/m, like => { binary_upgrade => 1, clean => 1, @@ -2200,7 +2200,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_sql => 'INSERT INTO dump_test.test_table (col1) ' . 'SELECT generate_series FROM generate_series(1,9);', regexp => qr/^ - \QCOPY test_table (col1, col2, col3, col4) FROM stdin;\E + \QCOPY dump_test.test_table (col1, col2, col3, col4) FROM stdin;\E \n(?:\d\t\\N\t\\N\t\\N\n){9}\\\.\n /xm, like => { @@ -2231,7 +2231,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_sql => 'INSERT INTO dump_test.fk_reference_test_table (col1) ' . 'SELECT generate_series FROM generate_series(1,5);', regexp => qr/^ - \QCOPY fk_reference_test_table (col1) FROM stdin;\E + \QCOPY dump_test.fk_reference_test_table (col1) FROM stdin;\E \n(?:\d\n){5}\\\.\n /xm, like => { @@ -2262,9 +2262,9 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp all_runs => 0, # really only for data-only catch_all => 'COPY ... commands', regexp => qr/^ - \QCOPY test_table (col1, col2, col3, col4) FROM stdin;\E + \QCOPY dump_test.test_table (col1, col2, col3, col4) FROM stdin;\E \n(?:\d\t\\N\t\\N\t\\N\n){9}\\\.\n.* - \QCOPY fk_reference_test_table (col1) FROM stdin;\E + \QCOPY dump_test.fk_reference_test_table (col1) FROM stdin;\E \n(?:\d\n){5}\\\.\n /xms, like => { data_only => 1, }, @@ -2278,7 +2278,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp . 'SELECT generate_series, generate_series::text ' . 'FROM generate_series(1,9);', regexp => qr/^ - \QCOPY test_second_table (col1, col2) FROM stdin;\E + \QCOPY dump_test.test_second_table (col1, col2) FROM stdin;\E \n(?:\d\t\d\n){9}\\\.\n /xm, like => { @@ -2310,7 +2310,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp 'INSERT INTO dump_test_second_schema.test_third_table (col1) ' . 'SELECT generate_series FROM generate_series(1,9);', regexp => qr/^ - \QCOPY test_third_table (col1) FROM stdin;\E + \QCOPY dump_test_second_schema.test_third_table (col1) FROM stdin;\E \n(?:\d\n){9}\\\.\n /xm, like => { @@ -2338,7 +2338,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp all_runs => 1, catch_all => 'COPY ... commands', regexp => qr/^ - \QCOPY test_third_table (col1) WITH OIDS FROM stdin;\E + \QCOPY dump_test_second_schema.test_third_table (col1) WITH OIDS FROM stdin;\E \n(?:\d+\t\d\n){9}\\\.\n /xm, like => { with_oids => 1, }, @@ -2368,7 +2368,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_sql => 'INSERT INTO dump_test.test_fourth_table DEFAULT VALUES;', regexp => qr/^ - \QCOPY test_fourth_table FROM stdin;\E + \QCOPY dump_test.test_fourth_table FROM stdin;\E \n\n\\\.\n /xm, like => { @@ -2399,7 +2399,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_sql => 'INSERT INTO dump_test.test_fifth_table VALUES (NULL, true, false, \'11001\'::bit(5), \'NaN\');', regexp => qr/^ - \QCOPY test_fifth_table (col1, col2, col3, col4, col5) FROM stdin;\E + \QCOPY dump_test.test_fifth_table (col1, col2, col3, col4, col5) FROM stdin;\E \n\\N\tt\tf\t11001\tNaN\n\\\.\n /xm, like => { @@ -2430,7 +2430,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp create_sql => 'INSERT INTO dump_test.test_table_identity (col2) VALUES (\'test\');', regexp => qr/^ - \QCOPY test_table_identity (col1, col2) FROM stdin;\E + \QCOPY dump_test.test_table_identity (col1, col2) FROM stdin;\E \n1\ttest\n\\\.\n /xm, like => { @@ -2471,7 +2471,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp all_runs => 1, catch_all => 'INSERT INTO ...', regexp => qr/^ - (?:INSERT\ INTO\ test_table\ \(col1,\ col2,\ col3,\ col4\)\ VALUES\ \(\d,\ NULL,\ NULL,\ NULL\);\n){9} + (?:INSERT\ INTO\ dump_test.test_table\ \(col1,\ col2,\ col3,\ col4\)\ VALUES\ \(\d,\ NULL,\ NULL,\ NULL\);\n){9} /xm, like => { column_inserts => 1, }, unlike => {}, }, @@ -2480,7 +2480,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp all_runs => 1, catch_all => 'INSERT INTO ...', regexp => qr/^ - (?:INSERT\ INTO\ test_second_table\ \(col1,\ col2\) + (?:INSERT\ INTO\ dump_test.test_second_table\ \(col1,\ col2\) \ VALUES\ \(\d,\ '\d'\);\n){9}/xm, like => { column_inserts => 1, }, unlike => {}, }, @@ -2489,7 +2489,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp all_runs => 1, catch_all => 'INSERT INTO ...', regexp => qr/^ - (?:INSERT\ INTO\ test_third_table\ \(col1\) + (?:INSERT\ INTO\ dump_test_second_schema.test_third_table\ \(col1\) \ VALUES\ \(\d\);\n){9}/xm, like => { column_inserts => 1, }, unlike => {}, }, @@ -2497,7 +2497,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp 'INSERT INTO test_fourth_table' => { all_runs => 1, catch_all => 'INSERT INTO ...', - regexp => qr/^\QINSERT INTO test_fourth_table DEFAULT VALUES;\E/m, + regexp => qr/^\QINSERT INTO dump_test.test_fourth_table DEFAULT VALUES;\E/m, like => { column_inserts => 1, }, unlike => {}, }, @@ -2505,7 +2505,7 @@ qr/^COMMENT ON TEXT SEARCH TEMPLATE alt_ts_temp1 IS 'comment on text search temp all_runs => 1, catch_all => 'INSERT INTO ...', regexp => -qr/^\QINSERT INTO test_fifth_table (col1, col2, col3, col4, col5) VALUES (NULL, true, false, B'11001', 'NaN');\E/m, +qr/^\QINSERT INTO dump_test.test_fifth_table (col1, col2, col3, col4, col5) VALUES (NULL, true, false, B'11001', 'NaN');\E/m, like => { column_inserts => 1, }, unlike => {}, }, @@ -2513,7 +2513,7 @@ qr/^\QINSERT INTO test_fifth_table (col1, col2, col3, col4, col5) VALUES (NULL, all_runs => 1, catch_all => 'INSERT INTO ...', regexp => -qr/^\QINSERT INTO test_table_identity (col1, col2) OVERRIDING SYSTEM VALUE VALUES (1, 'test');\E/m, +qr/^\QINSERT INTO dump_test.test_table_identity (col1, col2) OVERRIDING SYSTEM VALUE VALUES (1, 'test');\E/m, like => { column_inserts => 1, }, unlike => {}, }, @@ -2621,7 +2621,7 @@ qr/^\QINSERT INTO test_table_identity (col1, col2) OVERRIDING SYSTEM VALUE VALUE create_order => 76, create_sql => 'CREATE COLLATION test0 FROM "C";', regexp => qr/^ - \QCREATE COLLATION test0 (provider = libc, locale = 'C');\E/xm, + \QCREATE COLLATION public.test0 (provider = libc, locale = 'C');\E/xm, collation => 1, like => { binary_upgrade => 1, @@ -2793,7 +2793,7 @@ qr/CREATE CAST \(timestamp with time zone AS interval\) WITH FUNCTION pg_catalog initcond1 = \'{0,0}\' );', regexp => qr/^ - \QCREATE AGGREGATE newavg(integer) (\E + \QCREATE AGGREGATE dump_test.newavg(integer) (\E \n\s+\QSFUNC = int4_avg_accum,\E \n\s+\QSTYPE = bigint[],\E \n\s+\QINITCOND = '{0,0}',\E @@ -2834,7 +2834,7 @@ qr/CREATE CAST \(timestamp with time zone AS interval\) WITH FUNCTION pg_catalog create_sql => 'CREATE DEFAULT CONVERSION dump_test.test_conversion FOR \'LATIN1\' TO \'UTF8\' FROM iso8859_1_to_utf8;', regexp => -qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;\E/xm, +qr/^\QCREATE DEFAULT CONVERSION dump_test.test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;\E/xm, like => { binary_upgrade => 1, clean => 1, @@ -2872,7 +2872,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 CHECK(VALUE ~ \'^\d{5}$\' OR VALUE ~ \'^\d{5}-\d{4}$\');', regexp => qr/^ - \QCREATE DOMAIN us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+ + \QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+ \QCONSTRAINT us_postal_code_check CHECK \E \Q(((VALUE ~ '^\d{5}\E \$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$ @@ -2913,7 +2913,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 RETURNS LANGUAGE_HANDLER AS \'$libdir/plpgsql\', \'plpgsql_call_handler\' LANGUAGE C;', regexp => qr/^ - \QCREATE FUNCTION pltestlang_call_handler() \E + \QCREATE FUNCTION dump_test.pltestlang_call_handler() \E \QRETURNS language_handler\E \n\s+\QLANGUAGE c\E \n\s+AS\ \'\$ @@ -2954,7 +2954,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RETURN NULL; END;$$;', regexp => qr/^ - \QCREATE FUNCTION trigger_func() RETURNS trigger\E + \QCREATE FUNCTION dump_test.trigger_func() RETURNS trigger\E \n\s+\QLANGUAGE plpgsql\E \n\s+AS\ \$\$ \Q BEGIN RETURN NULL; END;\E @@ -2994,7 +2994,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 RETURNS event_trigger LANGUAGE plpgsql AS $$ BEGIN RETURN; END;$$;', regexp => qr/^ - \QCREATE FUNCTION event_trigger_func() RETURNS event_trigger\E + \QCREATE FUNCTION dump_test.event_trigger_func() RETURNS event_trigger\E \n\s+\QLANGUAGE plpgsql\E \n\s+AS\ \$\$ \Q BEGIN RETURN; END;\E @@ -3033,7 +3033,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE OPERATOR FAMILY dump_test.op_family USING btree;', regexp => qr/^ - \QCREATE OPERATOR FAMILY op_family USING btree;\E + \QCREATE OPERATOR FAMILY dump_test.op_family USING btree;\E /xm, like => { binary_upgrade => 1, @@ -3077,8 +3077,8 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 FUNCTION 1 btint8cmp(bigint,bigint), FUNCTION 2 btint8sortsupport(internal);', regexp => qr/^ - \QCREATE OPERATOR CLASS op_class\E\n\s+ - \QFOR TYPE bigint USING btree FAMILY op_family AS\E\n\s+ + \QCREATE OPERATOR CLASS dump_test.op_class\E\n\s+ + \QFOR TYPE bigint USING btree FAMILY dump_test.op_family AS\E\n\s+ \QOPERATOR 1 <(bigint,bigint) ,\E\n\s+ \QOPERATOR 2 <=(bigint,bigint) ,\E\n\s+ \QOPERATOR 3 =(bigint,bigint) ,\E\n\s+ @@ -3162,9 +3162,9 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 FOR EACH ROW WHEN (NEW.col1 > 10) EXECUTE PROCEDURE dump_test.trigger_func();', regexp => qr/^ - \QCREATE TRIGGER test_trigger BEFORE INSERT ON test_table \E + \QCREATE TRIGGER test_trigger BEFORE INSERT ON dump_test.test_table \E \QFOR EACH ROW WHEN ((new.col1 > 10)) \E - \QEXECUTE PROCEDURE trigger_func();\E + \QEXECUTE PROCEDURE dump_test.trigger_func();\E /xm, like => { binary_upgrade => 1, @@ -3200,7 +3200,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE TYPE dump_test.planets AS ENUM ( \'venus\', \'earth\', \'mars\' );', regexp => qr/^ - \QCREATE TYPE planets AS ENUM (\E + \QCREATE TYPE dump_test.planets AS ENUM (\E \n\s+'venus', \n\s+'earth', \n\s+'mars' @@ -3236,7 +3236,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 'CREATE TYPE dump_test.planets AS ENUM pg_upgrade' => { all_runs => 1, regexp => qr/^ - \QCREATE TYPE planets AS ENUM (\E + \QCREATE TYPE dump_test.planets AS ENUM (\E \n\);.*^ \QALTER TYPE dump_test.planets ADD VALUE 'venus';\E \n.*^ @@ -3278,7 +3278,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE TYPE dump_test.textrange AS RANGE (subtype=text, collation="C");', regexp => qr/^ - \QCREATE TYPE textrange AS RANGE (\E + \QCREATE TYPE dump_test.textrange AS RANGE (\E \n\s+\Qsubtype = text,\E \n\s+\Qcollation = pg_catalog."C"\E \n\);/xm, @@ -3314,7 +3314,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 all_runs => 1, create_order => 39, create_sql => 'CREATE TYPE dump_test.int42;', - regexp => qr/^CREATE TYPE int42;/m, + regexp => qr/^CREATE TYPE dump_test.int42;/m, like => { binary_upgrade => 1, clean => 1, @@ -3349,7 +3349,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1 (copy=english);', regexp => qr/^ - \QCREATE TEXT SEARCH CONFIGURATION alt_ts_conf1 (\E\n + \QCREATE TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1 (\E\n \s+\QPARSER = pg_catalog."default" );\E/xm, like => { binary_upgrade => 1, @@ -3382,61 +3382,61 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 'ALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1 ...' => { all_runs => 1, regexp => qr/^ - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR asciiword WITH english_stem;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR word WITH english_stem;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR numword WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR email WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR url WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR host WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR sfloat WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR version WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR hword_numpart WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR hword_part WITH english_stem;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR hword_asciipart WITH english_stem;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR numhword WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR asciihword WITH english_stem;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR hword WITH english_stem;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR url_path WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR file WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR "float" WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR "int" WITH simple;\E\n \n - \QALTER TEXT SEARCH CONFIGURATION alt_ts_conf1\E\n + \QALTER TEXT SEARCH CONFIGURATION dump_test.alt_ts_conf1\E\n \s+\QADD MAPPING FOR uint WITH simple;\E\n \n /xm, @@ -3474,7 +3474,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE TEXT SEARCH TEMPLATE dump_test.alt_ts_temp1 (lexize=dsimple_lexize);', regexp => qr/^ - \QCREATE TEXT SEARCH TEMPLATE alt_ts_temp1 (\E\n + \QCREATE TEXT SEARCH TEMPLATE dump_test.alt_ts_temp1 (\E\n \s+\QLEXIZE = dsimple_lexize );\E/xm, like => { binary_upgrade => 1, @@ -3510,7 +3510,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE TEXT SEARCH PARSER dump_test.alt_ts_prs1 (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);', regexp => qr/^ - \QCREATE TEXT SEARCH PARSER alt_ts_prs1 (\E\n + \QCREATE TEXT SEARCH PARSER dump_test.alt_ts_prs1 (\E\n \s+\QSTART = prsd_start,\E\n \s+\QGETTOKEN = prsd_nexttoken,\E\n \s+\QEND = prsd_end,\E\n @@ -3550,7 +3550,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE TEXT SEARCH DICTIONARY dump_test.alt_ts_dict1 (template=simple);', regexp => qr/^ - \QCREATE TEXT SEARCH DICTIONARY alt_ts_dict1 (\E\n + \QCREATE TEXT SEARCH DICTIONARY dump_test.alt_ts_dict1 (\E\n \s+\QTEMPLATE = pg_catalog.simple );\E\n /xm, like => { @@ -3588,7 +3588,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 RETURNS dump_test.int42 AS \'int4in\' LANGUAGE internal STRICT IMMUTABLE;', regexp => qr/^ - \QCREATE FUNCTION int42_in(cstring) RETURNS int42\E + \QCREATE FUNCTION dump_test.int42_in(cstring) RETURNS dump_test.int42\E \n\s+\QLANGUAGE internal IMMUTABLE STRICT\E \n\s+AS\ \$\$int4in\$\$; /xm, @@ -3627,7 +3627,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 RETURNS cstring AS \'int4out\' LANGUAGE internal STRICT IMMUTABLE;', regexp => qr/^ - \QCREATE FUNCTION int42_out(int42) RETURNS cstring\E + \QCREATE FUNCTION dump_test.int42_out(dump_test.int42) RETURNS cstring\E \n\s+\QLANGUAGE internal IMMUTABLE STRICT\E \n\s+AS\ \$\$int4out\$\$; /xm, @@ -3665,7 +3665,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 create_sql => 'CREATE PROCEDURE dump_test.ptest1(a int) LANGUAGE SQL AS $$ INSERT INTO dump_test.test_table (col1) VALUES (a) $$;', regexp => qr/^ - \QCREATE PROCEDURE ptest1(a integer)\E + \QCREATE PROCEDURE dump_test.ptest1(a integer)\E \n\s+\QLANGUAGE sql\E \n\s+AS\ \$\$\Q INSERT INTO dump_test.test_table (col1) VALUES (a) \E\$\$; /xm, @@ -3708,10 +3708,10 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 default = 42, passedbyvalue);', regexp => qr/^ - \QCREATE TYPE int42 (\E + \QCREATE TYPE dump_test.int42 (\E \n\s+\QINTERNALLENGTH = 4,\E - \n\s+\QINPUT = int42_in,\E - \n\s+\QOUTPUT = int42_out,\E + \n\s+\QINPUT = dump_test.int42_in,\E + \n\s+\QOUTPUT = dump_test.int42_out,\E \n\s+\QDEFAULT = '42',\E \n\s+\QALIGNMENT = int4,\E \n\s+\QSTORAGE = plain,\E @@ -3753,9 +3753,9 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 f2 dump_test.int42 );', regexp => qr/^ - \QCREATE TYPE composite AS (\E + \QCREATE TYPE dump_test.composite AS (\E \n\s+\Qf1 integer,\E - \n\s+\Qf2 int42\E + \n\s+\Qf2 dump_test.int42\E \n\); /xm, like => { @@ -3790,7 +3790,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 all_runs => 1, create_order => 39, create_sql => 'CREATE TYPE dump_test.undefined;', - regexp => qr/^CREATE TYPE undefined;/m, + regexp => qr/^CREATE TYPE dump_test.undefined;/m, like => { binary_upgrade => 1, clean => 1, @@ -3892,7 +3892,7 @@ qr/^\QCREATE DEFAULT CONVERSION test_conversion FOR 'LATIN1' TO 'UTF8' FROM iso8 'CREATE FOREIGN TABLE dump_test.foreign_table (c1 int options (column_name \'col1\')) SERVER s1 OPTIONS (schema_name \'x1\');', regexp => qr/ - \QCREATE FOREIGN TABLE foreign_table (\E\n + \QCREATE FOREIGN TABLE dump_test.foreign_table (\E\n \s+\Qc1 integer\E\n \Q)\E\n \QSERVER s1\E\n @@ -4006,7 +4006,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog HANDLER dump_test.pltestlang_call_handler;', regexp => qr/^ \QCREATE PROCEDURAL LANGUAGE pltestlang \E - \QHANDLER pltestlang_call_handler;\E + \QHANDLER dump_test.pltestlang_call_handler;\E /xm, like => { binary_upgrade => 1, @@ -4040,9 +4040,9 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE MATERIALIZED VIEW dump_test.matview (col1) AS SELECT col1 FROM dump_test.test_table;', regexp => qr/^ - \QCREATE MATERIALIZED VIEW matview AS\E + \QCREATE MATERIALIZED VIEW dump_test.matview AS\E \n\s+\QSELECT test_table.col1\E - \n\s+\QFROM test_table\E + \n\s+\QFROM dump_test.test_table\E \n\s+\QWITH NO DATA;\E /xm, like => { @@ -4078,9 +4078,9 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog dump_test.matview_second (col1) AS SELECT * FROM dump_test.matview;', regexp => qr/^ - \QCREATE MATERIALIZED VIEW matview_second AS\E + \QCREATE MATERIALIZED VIEW dump_test.matview_second AS\E \n\s+\QSELECT matview.col1\E - \n\s+\QFROM matview\E + \n\s+\QFROM dump_test.matview\E \n\s+\QWITH NO DATA;\E /xm, like => { @@ -4116,9 +4116,9 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog dump_test.matview_third (col1) AS SELECT * FROM dump_test.matview_second WITH NO DATA;', regexp => qr/^ - \QCREATE MATERIALIZED VIEW matview_third AS\E + \QCREATE MATERIALIZED VIEW dump_test.matview_third AS\E \n\s+\QSELECT matview_second.col1\E - \n\s+\QFROM matview_second\E + \n\s+\QFROM dump_test.matview_second\E \n\s+\QWITH NO DATA;\E /xm, like => { @@ -4154,9 +4154,9 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog dump_test.matview_fourth (col1) AS SELECT * FROM dump_test.matview_third WITH NO DATA;', regexp => qr/^ - \QCREATE MATERIALIZED VIEW matview_fourth AS\E + \QCREATE MATERIALIZED VIEW dump_test.matview_fourth AS\E \n\s+\QSELECT matview_third.col1\E - \n\s+\QFROM matview_third\E + \n\s+\QFROM dump_test.matview_third\E \n\s+\QWITH NO DATA;\E /xm, like => { @@ -4192,7 +4192,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog USING (true) WITH CHECK (true);', regexp => qr/^ - \QCREATE POLICY p1 ON test_table \E + \QCREATE POLICY p1 ON dump_test.test_table \E \QUSING (true) WITH CHECK (true);\E /xm, like => { @@ -4227,7 +4227,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE POLICY p2 ON dump_test.test_table FOR SELECT TO regress_dump_test_role USING (true);', regexp => qr/^ - \QCREATE POLICY p2 ON test_table FOR SELECT TO regress_dump_test_role \E + \QCREATE POLICY p2 ON dump_test.test_table FOR SELECT TO regress_dump_test_role \E \QUSING (true);\E /xm, like => { @@ -4262,7 +4262,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE POLICY p3 ON dump_test.test_table FOR INSERT TO regress_dump_test_role WITH CHECK (true);', regexp => qr/^ - \QCREATE POLICY p3 ON test_table FOR INSERT \E + \QCREATE POLICY p3 ON dump_test.test_table FOR INSERT \E \QTO regress_dump_test_role WITH CHECK (true);\E /xm, like => { @@ -4297,7 +4297,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE POLICY p4 ON dump_test.test_table FOR UPDATE TO regress_dump_test_role USING (true) WITH CHECK (true);', regexp => qr/^ - \QCREATE POLICY p4 ON test_table FOR UPDATE TO regress_dump_test_role \E + \QCREATE POLICY p4 ON dump_test.test_table FOR UPDATE TO regress_dump_test_role \E \QUSING (true) WITH CHECK (true);\E /xm, like => { @@ -4332,7 +4332,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE POLICY p5 ON dump_test.test_table FOR DELETE TO regress_dump_test_role USING (true);', regexp => qr/^ - \QCREATE POLICY p5 ON test_table FOR DELETE \E + \QCREATE POLICY p5 ON dump_test.test_table FOR DELETE \E \QTO regress_dump_test_role USING (true);\E /xm, like => { @@ -4367,7 +4367,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE POLICY p6 ON dump_test.test_table AS RESTRICTIVE USING (false);', regexp => qr/^ - \QCREATE POLICY p6 ON test_table AS RESTRICTIVE \E + \QCREATE POLICY p6 ON dump_test.test_table AS RESTRICTIVE \E \QUSING (false);\E /xm, like => { @@ -4505,7 +4505,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'ALTER PUBLICATION pub1 ADD TABLE dump_test.test_table;', regexp => qr/^ - \QALTER PUBLICATION pub1 ADD TABLE ONLY test_table;\E + \QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_table;\E /xm, like => { binary_upgrade => 1, @@ -4539,7 +4539,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'ALTER PUBLICATION pub1 ADD TABLE dump_test.test_second_table;', regexp => qr/^ - \QALTER PUBLICATION pub1 ADD TABLE ONLY test_second_table;\E + \QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_second_table;\E /xm, like => { binary_upgrade => 1, @@ -4667,7 +4667,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog CHECK (col1 <= 1000) ) WITH (autovacuum_enabled = false, fillfactor=80);', regexp => qr/^ - \QCREATE TABLE test_table (\E\n + \QCREATE TABLE dump_test.test_table (\E\n \s+\Qcol1 integer NOT NULL,\E\n \s+\Qcol2 text,\E\n \s+\Qcol3 text,\E\n @@ -4708,7 +4708,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog col1 int primary key references dump_test.test_table );', regexp => qr/^ - \QCREATE TABLE fk_reference_test_table (\E + \QCREATE TABLE dump_test.fk_reference_test_table (\E \n\s+\Qcol1 integer NOT NULL\E \n\); /xm, @@ -4746,7 +4746,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog col2 text );', regexp => qr/^ - \QCREATE TABLE test_second_table (\E + \QCREATE TABLE dump_test.test_second_table (\E \n\s+\Qcol1 integer,\E \n\s+\Qcol2 text\E \n\); @@ -4790,7 +4790,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog (\Q-- TOC entry \E[0-9]+\ \(class\ 1259\ OID\ [0-9]+\)\n)? \Q-- Name: test_third_table;\E.*\n \Q--\E\n\n - \QCREATE UNLOGGED TABLE test_third_table (\E + \QCREATE UNLOGGED TABLE dump_test_second_schema.test_third_table (\E \n\s+\Qcol1 integer NOT NULL\E \n\);\n /xm, @@ -4832,7 +4832,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog regexp => qr/^ \Q-- Name: measurement;\E.*\n \Q--\E\n\n - \QCREATE TABLE measurement (\E\n + \QCREATE TABLE dump_test.measurement (\E\n \s+\Qcity_id integer NOT NULL,\E\n \s+\Qlogdate date NOT NULL,\E\n \s+\Qpeaktemp integer,\E\n @@ -4876,7 +4876,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog regexp => qr/^ \Q-- Name: measurement_y2006m2;\E.*\n \Q--\E\n\n - \QCREATE TABLE measurement_y2006m2 PARTITION OF dump_test.measurement\E\n + \QCREATE TABLE dump_test_second_schema.measurement_y2006m2 PARTITION OF dump_test.measurement\E\n \QFOR VALUES FROM ('2006-02-01') TO ('2006-03-01');\E\n /xm, like => { @@ -4911,7 +4911,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE TABLE dump_test.test_fourth_table ( );', regexp => qr/^ - \QCREATE TABLE test_fourth_table (\E + \QCREATE TABLE dump_test.test_fourth_table (\E \n\); /xm, like => { @@ -4951,7 +4951,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog col5 float8 );', regexp => qr/^ - \QCREATE TABLE test_fifth_table (\E + \QCREATE TABLE dump_test.test_fifth_table (\E \n\s+\Qcol1 integer,\E \n\s+\Qcol2 boolean,\E \n\s+\Qcol3 boolean,\E @@ -4993,13 +4993,13 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog col2 text );', regexp => qr/^ - \QCREATE TABLE test_table_identity (\E\n + \QCREATE TABLE dump_test.test_table_identity (\E\n \s+\Qcol1 integer NOT NULL,\E\n \s+\Qcol2 text\E\n \); .* - \QALTER TABLE test_table_identity ALTER COLUMN col1 ADD GENERATED ALWAYS AS IDENTITY (\E\n - \s+\QSEQUENCE NAME test_table_identity_col1_seq\E\n + \QALTER TABLE dump_test.test_table_identity ALTER COLUMN col1 ADD GENERATED ALWAYS AS IDENTITY (\E\n + \s+\QSEQUENCE NAME dump_test.test_table_identity_col1_seq\E\n \s+\QSTART WITH 1\E\n \s+\QINCREMENT BY 1\E\n \s+\QNO MINVALUE\E\n @@ -5039,7 +5039,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_fifth_table', regexp => qr/^ - \QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM test_fifth_table;\E + \QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_fifth_table;\E /xms, like => { binary_upgrade => 1, @@ -5073,7 +5073,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_opts (ndistinct) ON col1, col2 FROM dump_test.test_fifth_table', regexp => qr/^ - \QCREATE STATISTICS dump_test.test_ext_stats_opts (ndistinct) ON col1, col2 FROM test_fifth_table;\E + \QCREATE STATISTICS dump_test.test_ext_stats_opts (ndistinct) ON col1, col2 FROM dump_test.test_fifth_table;\E /xms, like => { binary_upgrade => 1, @@ -5104,7 +5104,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog all_runs => 1, catch_all => 'CREATE ... commands', regexp => qr/^ - \QCREATE SEQUENCE test_table_col1_seq\E + \QCREATE SEQUENCE dump_test.test_table_col1_seq\E \n\s+\QAS integer\E \n\s+\QSTART WITH 1\E \n\s+\QINCREMENT BY 1\E @@ -5141,7 +5141,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog all_runs => 1, catch_all => 'CREATE ... commands', regexp => qr/^ - \QCREATE SEQUENCE test_third_table_col1_seq\E + \QCREATE SEQUENCE dump_test_second_schema.test_third_table_col1_seq\E \n\s+\QAS integer\E \n\s+\QSTART WITH 1\E \n\s+\QINCREMENT BY 1\E @@ -5182,7 +5182,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog ON dump_test_second_schema.test_third_table (col1);', regexp => qr/^ \QCREATE UNIQUE INDEX test_third_table_idx \E - \QON test_third_table USING btree (col1);\E + \QON dump_test_second_schema.test_third_table USING btree (col1);\E /xm, like => { binary_upgrade => 1, @@ -5215,7 +5215,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_order => 92, create_sql => 'CREATE INDEX ON dump_test.measurement (city_id, logdate);', regexp => qr/^ - \QCREATE INDEX measurement_city_id_logdate_idx ON ONLY measurement USING\E + \QCREATE INDEX measurement_city_id_logdate_idx ON ONLY dump_test.measurement USING\E /xm, like => { binary_upgrade => 1, @@ -5248,7 +5248,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_order => 93, create_sql => 'ALTER TABLE dump_test.measurement ADD PRIMARY KEY (city_id, logdate);', regexp => qr/^ - \QALTER TABLE ONLY measurement\E \n^\s+ + \QALTER TABLE ONLY dump_test.measurement\E \n^\s+ \QADD CONSTRAINT measurement_pkey PRIMARY KEY (city_id, logdate);\E /xm, like => { @@ -5280,7 +5280,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog all_runs => 1, catch_all => 'CREATE ... commands', regexp => qr/^ - \QCREATE INDEX measurement_y2006m2_city_id_logdate_idx ON measurement_y2006m2 \E + \QCREATE INDEX measurement_y2006m2_city_id_logdate_idx ON dump_test_second_schema.measurement_y2006m2 \E /xm, like => { binary_upgrade => 1, @@ -5377,9 +5377,9 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog WITH (check_option = \'local\', security_barrier = true) AS SELECT col1 FROM dump_test.test_table;', regexp => qr/^ - \QCREATE VIEW test_view WITH (security_barrier='true') AS\E + \QCREATE VIEW dump_test.test_view WITH (security_barrier='true') AS\E \n\s+\QSELECT test_table.col1\E - \n\s+\QFROM test_table\E + \n\s+\QFROM dump_test.test_table\E \n\s+\QWITH LOCAL CHECK OPTION;\E/xm, like => { binary_upgrade => 1, @@ -5413,7 +5413,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'ALTER VIEW dump_test.test_view ALTER COLUMN col1 SET DEFAULT 1;', regexp => qr/^ - \QALTER TABLE ONLY test_view ALTER COLUMN col1 SET DEFAULT 1;\E/xm, + \QALTER TABLE ONLY dump_test.test_view ALTER COLUMN col1 SET DEFAULT 1;\E/xm, like => { binary_upgrade => 1, clean => 1, @@ -5799,7 +5799,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'GRANT USAGE ON DOMAIN dump_test.us_postal_code TO regress_dump_test_role;', regexp => qr/^ - \QGRANT ALL ON TYPE us_postal_code TO regress_dump_test_role;\E + \QGRANT ALL ON TYPE dump_test.us_postal_code TO regress_dump_test_role;\E /xm, like => { binary_upgrade => 1, @@ -5836,7 +5836,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'GRANT USAGE ON TYPE dump_test.int42 TO regress_dump_test_role;', regexp => qr/^ - \QGRANT ALL ON TYPE int42 TO regress_dump_test_role;\E + \QGRANT ALL ON TYPE dump_test.int42 TO regress_dump_test_role;\E /xm, like => { binary_upgrade => 1, @@ -5873,7 +5873,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'GRANT USAGE ON TYPE dump_test.planets TO regress_dump_test_role;', regexp => qr/^ - \QGRANT ALL ON TYPE planets TO regress_dump_test_role;\E + \QGRANT ALL ON TYPE dump_test.planets TO regress_dump_test_role;\E /xm, like => { binary_upgrade => 1, @@ -5910,7 +5910,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'GRANT USAGE ON TYPE dump_test.textrange TO regress_dump_test_role;', regexp => qr/^ - \QGRANT ALL ON TYPE textrange TO regress_dump_test_role;\E + \QGRANT ALL ON TYPE dump_test.textrange TO regress_dump_test_role;\E /xm, like => { binary_upgrade => 1, @@ -5979,7 +5979,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog create_sql => 'GRANT SELECT ON TABLE dump_test.test_table TO regress_dump_test_role;', regexp => - qr/^GRANT SELECT ON TABLE test_table TO regress_dump_test_role;/m, + qr/^GRANT SELECT ON TABLE dump_test.test_table TO regress_dump_test_role;/m, like => { binary_upgrade => 1, clean => 1, @@ -6012,7 +6012,7 @@ qr/CREATE TRANSFORM FOR integer LANGUAGE sql \(FROM SQL WITH FUNCTION pg_catalog TABLE dump_test_second_schema.test_third_table TO regress_dump_test_role;', regexp => -qr/^GRANT SELECT ON TABLE test_third_table TO regress_dump_test_role;/m, +qr/^GRANT SELECT ON TABLE dump_test_second_schema.test_third_table TO regress_dump_test_role;/m, like => { binary_upgrade => 1, clean => 1, @@ -6045,7 +6045,7 @@ qr/^GRANT SELECT ON TABLE test_third_table TO regress_dump_test_role;/m, dump_test_second_schema.test_third_table_col1_seq TO regress_dump_test_role;', regexp => qr/^ - \QGRANT ALL ON SEQUENCE test_third_table_col1_seq TO regress_dump_test_role;\E + \QGRANT ALL ON SEQUENCE dump_test_second_schema.test_third_table_col1_seq TO regress_dump_test_role;\E /xm, like => { binary_upgrade => 1, @@ -6079,7 +6079,7 @@ qr/^GRANT SELECT ON TABLE test_third_table TO regress_dump_test_role;/m, TABLE dump_test.measurement TO regress_dump_test_role;', regexp => - qr/^GRANT SELECT ON TABLE measurement TO regress_dump_test_role;/m, + qr/^GRANT SELECT ON TABLE dump_test.measurement TO regress_dump_test_role;/m, like => { binary_upgrade => 1, clean => 1, @@ -6112,7 +6112,7 @@ qr/^GRANT SELECT ON TABLE test_third_table TO regress_dump_test_role;/m, TABLE dump_test_second_schema.measurement_y2006m2 TO regress_dump_test_role;', regexp => -qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, +qr/^GRANT SELECT ON TABLE dump_test_second_schema.measurement_y2006m2 TO regress_dump_test_role;/m, like => { binary_upgrade => 1, clean => 1, @@ -6183,7 +6183,7 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, 'GRANT INSERT (col1) ON TABLE dump_test.test_second_table TO regress_dump_test_role;', regexp => qr/^ - \QGRANT INSERT(col1) ON TABLE test_second_table TO regress_dump_test_role;\E + \QGRANT INSERT(col1) ON TABLE dump_test.test_second_table TO regress_dump_test_role;\E /xm, like => { binary_upgrade => 1, @@ -6216,7 +6216,7 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, create_sql => 'GRANT EXECUTE ON FUNCTION pg_sleep(float8) TO regress_dump_test_role;', regexp => qr/^ - \QGRANT ALL ON FUNCTION pg_sleep(double precision) TO regress_dump_test_role;\E + \QGRANT ALL ON FUNCTION pg_catalog.pg_sleep(double precision) TO regress_dump_test_role;\E /xm, like => { binary_upgrade => 1, @@ -6280,37 +6280,37 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, proacl ) ON TABLE pg_proc TO public;', regexp => qr/ - \QGRANT SELECT(tableoid) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(oid) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proname) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(pronamespace) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proowner) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(prolang) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(procost) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(prorows) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(provariadic) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(protransform) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proisagg) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proiswindow) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(prosecdef) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proleakproof) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proisstrict) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proretset) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(provolatile) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proparallel) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(pronargs) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(pronargdefaults) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(prorettype) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proargtypes) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proallargtypes) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proargmodes) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proargnames) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proargdefaults) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(protrftypes) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(prosrc) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(probin) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proconfig) ON TABLE pg_proc TO PUBLIC;\E\n.* - \QGRANT SELECT(proacl) ON TABLE pg_proc TO PUBLIC;\E/xms, + \QGRANT SELECT(tableoid) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(oid) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proname) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(pronamespace) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proowner) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(prolang) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(procost) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(prorows) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(provariadic) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(protransform) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proisagg) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proiswindow) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(prosecdef) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proleakproof) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proisstrict) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proretset) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(provolatile) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proparallel) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(pronargs) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(pronargdefaults) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(prorettype) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proargtypes) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proallargtypes) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proargmodes) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proargnames) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proargdefaults) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(protrftypes) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(prosrc) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(probin) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proconfig) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E\n.* + \QGRANT SELECT(proacl) ON TABLE pg_catalog.pg_proc TO PUBLIC;\E/xms, like => { binary_upgrade => 1, clean => 1, @@ -6376,7 +6376,7 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, 'REFRESH MATERIALIZED VIEW matview' => { all_runs => 1, - regexp => qr/^REFRESH MATERIALIZED VIEW matview;/m, + regexp => qr/^REFRESH MATERIALIZED VIEW dump_test.matview;/m, like => { clean => 1, clean_if_exists => 1, @@ -6408,9 +6408,9 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, 'REFRESH MATERIALIZED VIEW matview_second' => { all_runs => 1, regexp => qr/^ - \QREFRESH MATERIALIZED VIEW matview;\E + \QREFRESH MATERIALIZED VIEW dump_test.matview;\E \n.* - \QREFRESH MATERIALIZED VIEW matview_second;\E + \QREFRESH MATERIALIZED VIEW dump_test.matview_second;\E /xms, like => { clean => 1, @@ -6443,7 +6443,7 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, 'REFRESH MATERIALIZED VIEW matview_third' => { all_runs => 1, regexp => qr/^ - \QREFRESH MATERIALIZED VIEW matview_third;\E + \QREFRESH MATERIALIZED VIEW dump_test.matview_third;\E /xms, like => {}, unlike => { @@ -6476,7 +6476,7 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, 'REFRESH MATERIALIZED VIEW matview_fourth' => { all_runs => 1, regexp => qr/^ - \QREFRESH MATERIALIZED VIEW matview_fourth;\E + \QREFRESH MATERIALIZED VIEW dump_test.matview_fourth;\E /xms, like => {}, unlike => { @@ -6547,7 +6547,7 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, create_sql => 'REVOKE EXECUTE ON FUNCTION pg_sleep(float8) FROM public;', regexp => qr/^ - \QREVOKE ALL ON FUNCTION pg_sleep(double precision) FROM PUBLIC;\E + \QREVOKE ALL ON FUNCTION pg_catalog.pg_sleep(double precision) FROM PUBLIC;\E /xm, like => { binary_upgrade => 1, @@ -6578,7 +6578,7 @@ qr/^GRANT SELECT ON TABLE measurement_y2006m2 TO regress_dump_test_role;/m, catch_all => 'REVOKE commands', create_order => 45, create_sql => 'REVOKE SELECT ON TABLE pg_proc FROM public;', - regexp => qr/^REVOKE SELECT ON TABLE pg_proc FROM PUBLIC;/m, + regexp => qr/^REVOKE SELECT ON TABLE pg_catalog.pg_proc FROM PUBLIC;/m, like => { binary_upgrade => 1, clean => 1, diff --git a/src/test/modules/test_pg_dump/t/001_base.pl b/src/test/modules/test_pg_dump/t/001_base.pl index de70f4716be..fca00c64787 100644 --- a/src/test/modules/test_pg_dump/t/001_base.pl +++ b/src/test/modules/test_pg_dump/t/001_base.pl @@ -194,7 +194,7 @@ my %tests = ( create_sql => 'ALTER EXTENSION test_pg_dump ADD TABLE regress_pg_dump_table_added;', regexp => qr/^ - \QCREATE TABLE regress_pg_dump_table_added (\E + \QCREATE TABLE public.regress_pg_dump_table_added (\E \n\s+\Qcol1 integer NOT NULL,\E \n\s+\Qcol2 integer\E \n\);\n/xm, @@ -250,7 +250,7 @@ my %tests = ( 'CREATE SEQUENCE regress_pg_dump_table_col1_seq' => { regexp => qr/^ - \QCREATE SEQUENCE regress_pg_dump_table_col1_seq\E + \QCREATE SEQUENCE public.regress_pg_dump_table_col1_seq\E \n\s+\QAS integer\E \n\s+\QSTART WITH 1\E \n\s+\QINCREMENT BY 1\E @@ -276,7 +276,7 @@ my %tests = ( create_sql => 'CREATE TABLE regress_pg_dump_table_added (col1 int not null, col2 int);', regexp => qr/^ - \QCREATE TABLE regress_pg_dump_table_added (\E + \QCREATE TABLE public.regress_pg_dump_table_added (\E \n\s+\Qcol1 integer NOT NULL,\E \n\s+\Qcol2 integer\E \n\);\n/xm, @@ -295,7 +295,7 @@ my %tests = ( 'CREATE SEQUENCE regress_pg_dump_seq' => { regexp => qr/^ - \QCREATE SEQUENCE regress_pg_dump_seq\E + \QCREATE SEQUENCE public.regress_pg_dump_seq\E \n\s+\QSTART WITH 1\E \n\s+\QINCREMENT BY 1\E \n\s+\QNO MINVALUE\E @@ -319,7 +319,7 @@ my %tests = ( create_order => 6, create_sql => qq{SELECT nextval('regress_seq_dumpable');}, regexp => qr/^ - \QSELECT pg_catalog.setval('regress_seq_dumpable', 1, true);\E + \QSELECT pg_catalog.setval('public.regress_seq_dumpable', 1, true);\E \n/xm, like => { clean => 1, @@ -337,7 +337,7 @@ my %tests = ( 'CREATE TABLE regress_pg_dump_table' => { regexp => qr/^ - \QCREATE TABLE regress_pg_dump_table (\E + \QCREATE TABLE public.regress_pg_dump_table (\E \n\s+\Qcol1 integer NOT NULL,\E \n\s+\Qcol2 integer\E \n\);\n/xm, @@ -395,7 +395,7 @@ my %tests = ( create_sql => 'GRANT SELECT ON regress_pg_dump_table_added TO regress_dump_test_role;', regexp => qr/^ - \QGRANT SELECT ON TABLE regress_pg_dump_table_added TO regress_dump_test_role;\E + \QGRANT SELECT ON TABLE public.regress_pg_dump_table_added TO regress_dump_test_role;\E \n/xm, like => { binary_upgrade => 1, }, unlike => { @@ -415,7 +415,7 @@ my %tests = ( create_sql => 'REVOKE SELECT ON regress_pg_dump_table_added FROM regress_dump_test_role;', regexp => qr/^ - \QREVOKE SELECT ON TABLE regress_pg_dump_table_added FROM regress_dump_test_role;\E + \QREVOKE SELECT ON TABLE public.regress_pg_dump_table_added FROM regress_dump_test_role;\E \n/xm, like => { binary_upgrade => 1, @@ -434,7 +434,7 @@ my %tests = ( 'GRANT SELECT ON TABLE regress_pg_dump_table' => { regexp => qr/^ \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\E\n - \QGRANT SELECT ON TABLE regress_pg_dump_table TO regress_dump_test_role;\E\n + \QGRANT SELECT ON TABLE public.regress_pg_dump_table TO regress_dump_test_role;\E\n \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\E \n/xms, like => { binary_upgrade => 1, }, @@ -453,7 +453,7 @@ my %tests = ( 'GRANT SELECT(col1) ON regress_pg_dump_table' => { regexp => qr/^ \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\E\n - \QGRANT SELECT(col1) ON TABLE regress_pg_dump_table TO PUBLIC;\E\n + \QGRANT SELECT(col1) ON TABLE public.regress_pg_dump_table TO PUBLIC;\E\n \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\E \n/xms, like => { binary_upgrade => 1, }, @@ -474,7 +474,7 @@ my %tests = ( create_sql => 'GRANT SELECT(col2) ON regress_pg_dump_table TO regress_dump_test_role;', regexp => qr/^ - \QGRANT SELECT(col2) ON TABLE regress_pg_dump_table TO regress_dump_test_role;\E + \QGRANT SELECT(col2) ON TABLE public.regress_pg_dump_table TO regress_dump_test_role;\E \n/xm, like => { binary_upgrade => 1, @@ -496,7 +496,7 @@ my %tests = ( create_sql => 'GRANT USAGE ON SEQUENCE regress_pg_dump_table_col1_seq TO regress_dump_test_role;', regexp => qr/^ - \QGRANT USAGE ON SEQUENCE regress_pg_dump_table_col1_seq TO regress_dump_test_role;\E + \QGRANT USAGE ON SEQUENCE public.regress_pg_dump_table_col1_seq TO regress_dump_test_role;\E \n/xm, like => { binary_upgrade => 1, @@ -514,7 +514,7 @@ my %tests = ( 'GRANT USAGE ON regress_pg_dump_seq TO regress_dump_test_role' => { regexp => qr/^ - \QGRANT USAGE ON SEQUENCE regress_pg_dump_seq TO regress_dump_test_role;\E + \QGRANT USAGE ON SEQUENCE public.regress_pg_dump_seq TO regress_dump_test_role;\E \n/xm, like => { binary_upgrade => 1, }, unlike => { @@ -534,7 +534,7 @@ my %tests = ( create_sql => 'REVOKE SELECT(col1) ON regress_pg_dump_table FROM PUBLIC;', regexp => qr/^ - \QREVOKE SELECT(col1) ON TABLE regress_pg_dump_table FROM PUBLIC;\E + \QREVOKE SELECT(col1) ON TABLE public.regress_pg_dump_table FROM PUBLIC;\E \n/xm, like => { binary_upgrade => 1, @@ -553,7 +553,7 @@ my %tests = ( # Objects included in extension part of a schema created by this extension */ 'CREATE TABLE regress_pg_dump_schema.test_table' => { regexp => qr/^ - \QCREATE TABLE test_table (\E + \QCREATE TABLE regress_pg_dump_schema.test_table (\E \n\s+\Qcol1 integer,\E \n\s+\Qcol2 integer\E \n\);\n/xm, @@ -573,7 +573,7 @@ my %tests = ( 'GRANT SELECT ON regress_pg_dump_schema.test_table' => { regexp => qr/^ \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\E\n - \QGRANT SELECT ON TABLE test_table TO regress_dump_test_role;\E\n + \QGRANT SELECT ON TABLE regress_pg_dump_schema.test_table TO regress_dump_test_role;\E\n \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\E \n/xms, like => { binary_upgrade => 1, }, @@ -591,7 +591,7 @@ my %tests = ( 'CREATE SEQUENCE regress_pg_dump_schema.test_seq' => { regexp => qr/^ - \QCREATE SEQUENCE test_seq\E + \QCREATE SEQUENCE regress_pg_dump_schema.test_seq\E \n\s+\QSTART WITH 1\E \n\s+\QINCREMENT BY 1\E \n\s+\QNO MINVALUE\E @@ -614,7 +614,7 @@ my %tests = ( 'GRANT USAGE ON regress_pg_dump_schema.test_seq' => { regexp => qr/^ \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\E\n - \QGRANT USAGE ON SEQUENCE test_seq TO regress_dump_test_role;\E\n + \QGRANT USAGE ON SEQUENCE regress_pg_dump_schema.test_seq TO regress_dump_test_role;\E\n \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\E \n/xms, like => { binary_upgrade => 1, }, @@ -632,7 +632,7 @@ my %tests = ( 'CREATE TYPE regress_pg_dump_schema.test_type' => { regexp => qr/^ - \QCREATE TYPE test_type AS (\E + \QCREATE TYPE regress_pg_dump_schema.test_type AS (\E \n\s+\Qcol1 integer\E \n\);\n/xm, like => { binary_upgrade => 1, }, @@ -651,7 +651,7 @@ my %tests = ( 'GRANT USAGE ON regress_pg_dump_schema.test_type' => { regexp => qr/^ \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\E\n - \QGRANT ALL ON TYPE test_type TO regress_dump_test_role;\E\n + \QGRANT ALL ON TYPE regress_pg_dump_schema.test_type TO regress_dump_test_role;\E\n \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\E \n/xms, like => { binary_upgrade => 1, }, @@ -669,7 +669,7 @@ my %tests = ( 'CREATE FUNCTION regress_pg_dump_schema.test_func' => { regexp => qr/^ - \QCREATE FUNCTION test_func() RETURNS integer\E + \QCREATE FUNCTION regress_pg_dump_schema.test_func() RETURNS integer\E \n\s+\QLANGUAGE sql\E \n/xm, like => { binary_upgrade => 1, }, @@ -688,7 +688,7 @@ my %tests = ( 'GRANT ALL ON regress_pg_dump_schema.test_func' => { regexp => qr/^ \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\E\n - \QGRANT ALL ON FUNCTION test_func() TO regress_dump_test_role;\E\n + \QGRANT ALL ON FUNCTION regress_pg_dump_schema.test_func() TO regress_dump_test_role;\E\n \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\E \n/xms, like => { binary_upgrade => 1, }, @@ -706,7 +706,7 @@ my %tests = ( 'CREATE AGGREGATE regress_pg_dump_schema.test_agg' => { regexp => qr/^ - \QCREATE AGGREGATE test_agg(smallint) (\E + \QCREATE AGGREGATE regress_pg_dump_schema.test_agg(smallint) (\E \n\s+\QSFUNC = int2_sum,\E \n\s+\QSTYPE = bigint\E \n\);\n/xm, @@ -726,7 +726,7 @@ my %tests = ( 'GRANT ALL ON regress_pg_dump_schema.test_agg' => { regexp => qr/^ \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\E\n - \QGRANT ALL ON FUNCTION test_agg(smallint) TO regress_dump_test_role;\E\n + \QGRANT ALL ON FUNCTION regress_pg_dump_schema.test_agg(smallint) TO regress_dump_test_role;\E\n \QSELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\E \n/xms, like => { binary_upgrade => 1, }, @@ -748,7 +748,7 @@ my %tests = ( create_sql => 'CREATE TABLE regress_pg_dump_schema.external_tab (col1 int);', regexp => qr/^ - \QCREATE TABLE external_tab (\E + \QCREATE TABLE regress_pg_dump_schema.external_tab (\E \n\s+\Qcol1 integer\E \n\);\n/xm, like => { diff --git a/src/test/regress/expected/collate.icu.utf8.out b/src/test/regress/expected/collate.icu.utf8.out index e1fc9984f2f..e8cf5d50d1d 100644 --- a/src/test/regress/expected/collate.icu.utf8.out +++ b/src/test/regress/expected/collate.icu.utf8.out @@ -968,12 +968,12 @@ ERROR: collations are not supported by type integer LINE 1: ...ATE INDEX collate_test1_idx6 ON collate_test1 ((a COLLATE "C... ^ SELECT relname, pg_get_indexdef(oid) FROM pg_class WHERE relname LIKE 'collate_test%_idx%' ORDER BY 1; - relname | pg_get_indexdef ---------------------+----------------------------------------------------------------------------------------------------- - collate_test1_idx1 | CREATE INDEX collate_test1_idx1 ON collate_test1 USING btree (b) - collate_test1_idx2 | CREATE INDEX collate_test1_idx2 ON collate_test1 USING btree (b COLLATE "C") - collate_test1_idx3 | CREATE INDEX collate_test1_idx3 ON collate_test1 USING btree (b COLLATE "C") - collate_test1_idx4 | CREATE INDEX collate_test1_idx4 ON collate_test1 USING btree (((b || 'foo'::text)) COLLATE "POSIX") + relname | pg_get_indexdef +--------------------+------------------------------------------------------------------------------------------------------------------- + collate_test1_idx1 | CREATE INDEX collate_test1_idx1 ON collate_tests.collate_test1 USING btree (b) + collate_test1_idx2 | CREATE INDEX collate_test1_idx2 ON collate_tests.collate_test1 USING btree (b COLLATE "C") + collate_test1_idx3 | CREATE INDEX collate_test1_idx3 ON collate_tests.collate_test1 USING btree (b COLLATE "C") + collate_test1_idx4 | CREATE INDEX collate_test1_idx4 ON collate_tests.collate_test1 USING btree (((b || 'foo'::text)) COLLATE "POSIX") (4 rows) -- schema manipulation commands diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out index 6b7318613a3..4eb2322e539 100644 --- a/src/test/regress/expected/collate.linux.utf8.out +++ b/src/test/regress/expected/collate.linux.utf8.out @@ -977,12 +977,12 @@ ERROR: collations are not supported by type integer LINE 1: ...ATE INDEX collate_test1_idx6 ON collate_test1 ((a COLLATE "C... ^ SELECT relname, pg_get_indexdef(oid) FROM pg_class WHERE relname LIKE 'collate_test%_idx%' ORDER BY 1; - relname | pg_get_indexdef ---------------------+----------------------------------------------------------------------------------------------------- - collate_test1_idx1 | CREATE INDEX collate_test1_idx1 ON collate_test1 USING btree (b) - collate_test1_idx2 | CREATE INDEX collate_test1_idx2 ON collate_test1 USING btree (b COLLATE "C") - collate_test1_idx3 | CREATE INDEX collate_test1_idx3 ON collate_test1 USING btree (b COLLATE "C") - collate_test1_idx4 | CREATE INDEX collate_test1_idx4 ON collate_test1 USING btree (((b || 'foo'::text)) COLLATE "POSIX") + relname | pg_get_indexdef +--------------------+------------------------------------------------------------------------------------------------------------------- + collate_test1_idx1 | CREATE INDEX collate_test1_idx1 ON collate_tests.collate_test1 USING btree (b) + collate_test1_idx2 | CREATE INDEX collate_test1_idx2 ON collate_tests.collate_test1 USING btree (b COLLATE "C") + collate_test1_idx3 | CREATE INDEX collate_test1_idx3 ON collate_tests.collate_test1 USING btree (b COLLATE "C") + collate_test1_idx4 | CREATE INDEX collate_test1_idx4 ON collate_tests.collate_test1 USING btree (((b || 'foo'::text)) COLLATE "POSIX") (4 rows) -- schema manipulation commands diff --git a/src/test/regress/expected/collate.out b/src/test/regress/expected/collate.out index 3bc3713ee1b..f045f2b291c 100644 --- a/src/test/regress/expected/collate.out +++ b/src/test/regress/expected/collate.out @@ -572,12 +572,12 @@ ERROR: collations are not supported by type integer LINE 1: ...ATE INDEX collate_test1_idx6 ON collate_test1 ((a COLLATE "P... ^ SELECT relname, pg_get_indexdef(oid) FROM pg_class WHERE relname LIKE 'collate_test%_idx%' ORDER BY 1; - relname | pg_get_indexdef ---------------------+----------------------------------------------------------------------------------------------------- - collate_test1_idx1 | CREATE INDEX collate_test1_idx1 ON collate_test1 USING btree (b) - collate_test1_idx2 | CREATE INDEX collate_test1_idx2 ON collate_test1 USING btree (b COLLATE "POSIX") - collate_test1_idx3 | CREATE INDEX collate_test1_idx3 ON collate_test1 USING btree (b COLLATE "POSIX") - collate_test1_idx4 | CREATE INDEX collate_test1_idx4 ON collate_test1 USING btree (((b || 'foo'::text)) COLLATE "POSIX") + relname | pg_get_indexdef +--------------------+------------------------------------------------------------------------------------------------------------------- + collate_test1_idx1 | CREATE INDEX collate_test1_idx1 ON collate_tests.collate_test1 USING btree (b) + collate_test1_idx2 | CREATE INDEX collate_test1_idx2 ON collate_tests.collate_test1 USING btree (b COLLATE "POSIX") + collate_test1_idx3 | CREATE INDEX collate_test1_idx3 ON collate_tests.collate_test1 USING btree (b COLLATE "POSIX") + collate_test1_idx4 | CREATE INDEX collate_test1_idx4 ON collate_tests.collate_test1 USING btree (((b || 'foo'::text)) COLLATE "POSIX") (4 rows) -- foreign keys diff --git a/src/test/regress/expected/indexing.out b/src/test/regress/expected/indexing.out index 85e3575b99d..375f55b3378 100644 --- a/src/test/regress/expected/indexing.out +++ b/src/test/regress/expected/indexing.out @@ -487,11 +487,11 @@ select relname as child, inhparent::regclass as parent, pg_get_indexdef as child from pg_class join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; - child | parent | childdef --------------------+------------------+-------------------------------------------------------------------- - idxpart1_expr_idx | idxpart_expr_idx | CREATE INDEX idxpart1_expr_idx ON idxpart1 USING btree (((a + b))) - idxpart2_expr_idx | idxpart_expr_idx | CREATE INDEX idxpart2_expr_idx ON idxpart2 USING btree (((a + b))) - idxpart3_expr_idx | idxpart_expr_idx | CREATE INDEX idxpart3_expr_idx ON idxpart3 USING btree (((a + b))) + child | parent | childdef +-------------------+------------------+--------------------------------------------------------------------------- + idxpart1_expr_idx | idxpart_expr_idx | CREATE INDEX idxpart1_expr_idx ON public.idxpart1 USING btree (((a + b))) + idxpart2_expr_idx | idxpart_expr_idx | CREATE INDEX idxpart2_expr_idx ON public.idxpart2 USING btree (((a + b))) + idxpart3_expr_idx | idxpart_expr_idx | CREATE INDEX idxpart3_expr_idx ON public.idxpart3 USING btree (((a + b))) (3 rows) drop table idxpart; @@ -511,15 +511,15 @@ select relname as child, inhparent::regclass as parent, pg_get_indexdef as child from pg_class left join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; - child | parent | childdef ------------------+---------------+------------------------------------------------------------------------- - idxpart1_a_idx | idxpart_a_idx | CREATE INDEX idxpart1_a_idx ON idxpart1 USING btree (a COLLATE "C") - idxpart2_a_idx | | CREATE INDEX idxpart2_a_idx ON idxpart2 USING btree (a COLLATE "POSIX") - idxpart2_a_idx1 | | CREATE INDEX idxpart2_a_idx1 ON idxpart2 USING btree (a) - idxpart2_a_idx2 | idxpart_a_idx | CREATE INDEX idxpart2_a_idx2 ON idxpart2 USING btree (a COLLATE "C") - idxpart3_a_idx | idxpart_a_idx | CREATE INDEX idxpart3_a_idx ON idxpart3 USING btree (a COLLATE "C") - idxpart4_a_idx | idxpart_a_idx | CREATE INDEX idxpart4_a_idx ON idxpart4 USING btree (a COLLATE "C") - idxpart_a_idx | | CREATE INDEX idxpart_a_idx ON ONLY idxpart USING btree (a COLLATE "C") + child | parent | childdef +-----------------+---------------+-------------------------------------------------------------------------------- + idxpart1_a_idx | idxpart_a_idx | CREATE INDEX idxpart1_a_idx ON public.idxpart1 USING btree (a COLLATE "C") + idxpart2_a_idx | | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a COLLATE "POSIX") + idxpart2_a_idx1 | | CREATE INDEX idxpart2_a_idx1 ON public.idxpart2 USING btree (a) + idxpart2_a_idx2 | idxpart_a_idx | CREATE INDEX idxpart2_a_idx2 ON public.idxpart2 USING btree (a COLLATE "C") + idxpart3_a_idx | idxpart_a_idx | CREATE INDEX idxpart3_a_idx ON public.idxpart3 USING btree (a COLLATE "C") + idxpart4_a_idx | idxpart_a_idx | CREATE INDEX idxpart4_a_idx ON public.idxpart4 USING btree (a COLLATE "C") + idxpart_a_idx | | CREATE INDEX idxpart_a_idx ON ONLY public.idxpart USING btree (a COLLATE "C") (7 rows) drop table idxpart; @@ -538,14 +538,14 @@ select relname as child, inhparent::regclass as parent, pg_get_indexdef as child from pg_class left join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; - child | parent | childdef ------------------+---------------+----------------------------------------------------------------------------- - idxpart1_a_idx | idxpart_a_idx | CREATE INDEX idxpart1_a_idx ON idxpart1 USING btree (a text_pattern_ops) - idxpart2_a_idx | | CREATE INDEX idxpart2_a_idx ON idxpart2 USING btree (a) - idxpart2_a_idx1 | idxpart_a_idx | CREATE INDEX idxpart2_a_idx1 ON idxpart2 USING btree (a text_pattern_ops) - idxpart3_a_idx | idxpart_a_idx | CREATE INDEX idxpart3_a_idx ON idxpart3 USING btree (a text_pattern_ops) - idxpart4_a_idx | idxpart_a_idx | CREATE INDEX idxpart4_a_idx ON idxpart4 USING btree (a text_pattern_ops) - idxpart_a_idx | | CREATE INDEX idxpart_a_idx ON ONLY idxpart USING btree (a text_pattern_ops) + child | parent | childdef +-----------------+---------------+------------------------------------------------------------------------------------ + idxpart1_a_idx | idxpart_a_idx | CREATE INDEX idxpart1_a_idx ON public.idxpart1 USING btree (a text_pattern_ops) + idxpart2_a_idx | | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a) + idxpart2_a_idx1 | idxpart_a_idx | CREATE INDEX idxpart2_a_idx1 ON public.idxpart2 USING btree (a text_pattern_ops) + idxpart3_a_idx | idxpart_a_idx | CREATE INDEX idxpart3_a_idx ON public.idxpart3 USING btree (a text_pattern_ops) + idxpart4_a_idx | idxpart_a_idx | CREATE INDEX idxpart4_a_idx ON public.idxpart4 USING btree (a text_pattern_ops) + idxpart_a_idx | | CREATE INDEX idxpart_a_idx ON ONLY public.idxpart USING btree (a text_pattern_ops) (6 rows) drop index idxpart_a_idx; @@ -584,15 +584,15 @@ select relname as child, inhparent::regclass as parent, pg_get_indexdef as child from pg_class left join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; - child | parent | childdef ------------------+---------------+---------------------------------------------------------------------------------- - idxpart1_1_idx | idxpart_1_idx | CREATE INDEX idxpart1_1_idx ON idxpart1 USING btree (b, a) - idxpart1_1b_idx | | CREATE INDEX idxpart1_1b_idx ON idxpart1 USING btree (b) - idxpart1_2_idx | idxpart_2_idx | CREATE INDEX idxpart1_2_idx ON idxpart1 USING btree (((b + a))) WHERE (a > 1) - idxpart1_2b_idx | | CREATE INDEX idxpart1_2b_idx ON idxpart1 USING btree (((a + b))) WHERE (a > 1) - idxpart1_2c_idx | | CREATE INDEX idxpart1_2c_idx ON idxpart1 USING btree (((b + a))) WHERE (b > 1) - idxpart_1_idx | | CREATE INDEX idxpart_1_idx ON ONLY idxpart USING btree (b, a) - idxpart_2_idx | | CREATE INDEX idxpart_2_idx ON ONLY idxpart USING btree (((b + a))) WHERE (a > 1) + child | parent | childdef +-----------------+---------------+----------------------------------------------------------------------------------------- + idxpart1_1_idx | idxpart_1_idx | CREATE INDEX idxpart1_1_idx ON public.idxpart1 USING btree (b, a) + idxpart1_1b_idx | | CREATE INDEX idxpart1_1b_idx ON public.idxpart1 USING btree (b) + idxpart1_2_idx | idxpart_2_idx | CREATE INDEX idxpart1_2_idx ON public.idxpart1 USING btree (((b + a))) WHERE (a > 1) + idxpart1_2b_idx | | CREATE INDEX idxpart1_2b_idx ON public.idxpart1 USING btree (((a + b))) WHERE (a > 1) + idxpart1_2c_idx | | CREATE INDEX idxpart1_2c_idx ON public.idxpart1 USING btree (((b + a))) WHERE (b > 1) + idxpart_1_idx | | CREATE INDEX idxpart_1_idx ON ONLY public.idxpart USING btree (b, a) + idxpart_2_idx | | CREATE INDEX idxpart_2_idx ON ONLY public.idxpart USING btree (((b + a))) WHERE (a > 1) (7 rows) drop table idxpart; @@ -610,14 +610,14 @@ select c.relname, pg_get_indexdef(indexrelid) from pg_class c join pg_index i on c.oid = i.indexrelid where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - relname | pg_get_indexdef -------------------+-------------------------------------------------------------- - idxpart1_a_idx | CREATE INDEX idxpart1_a_idx ON idxpart1 USING btree (a) - idxpart1_c_b_idx | CREATE INDEX idxpart1_c_b_idx ON idxpart1 USING btree (c, b) - idxpart2_a_idx | CREATE INDEX idxpart2_a_idx ON idxpart2 USING btree (a) - idxpart2_c_b_idx | CREATE INDEX idxpart2_c_b_idx ON idxpart2 USING btree (c, b) - idxparti | CREATE INDEX idxparti ON ONLY idxpart USING btree (a) - idxparti2 | CREATE INDEX idxparti2 ON ONLY idxpart USING btree (c, b) + relname | pg_get_indexdef +------------------+--------------------------------------------------------------------- + idxpart1_a_idx | CREATE INDEX idxpart1_a_idx ON public.idxpart1 USING btree (a) + idxpart1_c_b_idx | CREATE INDEX idxpart1_c_b_idx ON public.idxpart1 USING btree (c, b) + idxpart2_a_idx | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a) + idxpart2_c_b_idx | CREATE INDEX idxpart2_c_b_idx ON public.idxpart2 USING btree (c, b) + idxparti | CREATE INDEX idxparti ON ONLY public.idxpart USING btree (a) + idxparti2 | CREATE INDEX idxparti2 ON ONLY public.idxpart USING btree (c, b) (6 rows) drop table idxpart; @@ -636,11 +636,11 @@ select c.relname, pg_get_indexdef(indexrelid) from pg_class c join pg_index i on c.oid = i.indexrelid where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - relname | pg_get_indexdef -------------------+------------------------------------------------------------------- - idxpart1_abs_idx | CREATE INDEX idxpart1_abs_idx ON idxpart1 USING btree (abs(b)) - idxpart2_abs_idx | CREATE INDEX idxpart2_abs_idx ON idxpart2 USING btree (abs(b)) - idxpart_abs_idx | CREATE INDEX idxpart_abs_idx ON ONLY idxpart USING btree (abs(b)) + relname | pg_get_indexdef +------------------+-------------------------------------------------------------------------- + idxpart1_abs_idx | CREATE INDEX idxpart1_abs_idx ON public.idxpart1 USING btree (abs(b)) + idxpart2_abs_idx | CREATE INDEX idxpart2_abs_idx ON public.idxpart2 USING btree (abs(b)) + idxpart_abs_idx | CREATE INDEX idxpart_abs_idx ON ONLY public.idxpart USING btree (abs(b)) (3 rows) drop table idxpart; @@ -659,11 +659,11 @@ select c.relname, pg_get_indexdef(indexrelid) from pg_class c join pg_index i on c.oid = i.indexrelid where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - relname | pg_get_indexdef -----------------+----------------------------------------------------------------------------- - idxpart1_a_idx | CREATE INDEX idxpart1_a_idx ON idxpart1 USING btree (a) WHERE (b > 1000) - idxpart2_a_idx | CREATE INDEX idxpart2_a_idx ON idxpart2 USING btree (a) WHERE (b > 1000) - idxpart_a_idx | CREATE INDEX idxpart_a_idx ON ONLY idxpart USING btree (a) WHERE (b > 1000) + relname | pg_get_indexdef +----------------+------------------------------------------------------------------------------------ + idxpart1_a_idx | CREATE INDEX idxpart1_a_idx ON public.idxpart1 USING btree (a) WHERE (b > 1000) + idxpart2_a_idx | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a) WHERE (b > 1000) + idxpart_a_idx | CREATE INDEX idxpart_a_idx ON ONLY public.idxpart USING btree (a) WHERE (b > 1000) (3 rows) drop table idxpart; diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 5433944c6a0..5acb92f30fa 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -2342,103 +2342,103 @@ toyemp| SELECT emp.name, SELECT tablename, rulename, definition FROM pg_rules ORDER BY tablename, rulename; pg_settings|pg_settings_n|CREATE RULE pg_settings_n AS - ON UPDATE TO pg_settings DO INSTEAD NOTHING; + ON UPDATE TO pg_catalog.pg_settings DO INSTEAD NOTHING; pg_settings|pg_settings_u|CREATE RULE pg_settings_u AS - ON UPDATE TO pg_settings + ON UPDATE TO pg_catalog.pg_settings WHERE (new.name = old.name) DO SELECT set_config(old.name, new.setting, false) AS set_config; rtest_emp|rtest_emp_del|CREATE RULE rtest_emp_del AS - ON DELETE TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, action, newsal, oldsal) + ON DELETE TO public.rtest_emp DO INSERT INTO rtest_emplog (ename, who, action, newsal, oldsal) VALUES (old.ename, CURRENT_USER, 'fired'::bpchar, '$0.00'::money, old.salary); rtest_emp|rtest_emp_ins|CREATE RULE rtest_emp_ins AS - ON INSERT TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, action, newsal, oldsal) + ON INSERT TO public.rtest_emp DO INSERT INTO rtest_emplog (ename, who, action, newsal, oldsal) VALUES (new.ename, CURRENT_USER, 'hired'::bpchar, new.salary, '$0.00'::money); rtest_emp|rtest_emp_upd|CREATE RULE rtest_emp_upd AS - ON UPDATE TO rtest_emp + ON UPDATE TO public.rtest_emp WHERE (new.salary <> old.salary) DO INSERT INTO rtest_emplog (ename, who, action, newsal, oldsal) VALUES (new.ename, CURRENT_USER, 'honored'::bpchar, new.salary, old.salary); rtest_nothn1|rtest_nothn_r1|CREATE RULE rtest_nothn_r1 AS - ON INSERT TO rtest_nothn1 + ON INSERT TO public.rtest_nothn1 WHERE ((new.a >= 10) AND (new.a < 20)) DO INSTEAD NOTHING; rtest_nothn1|rtest_nothn_r2|CREATE RULE rtest_nothn_r2 AS - ON INSERT TO rtest_nothn1 + ON INSERT TO public.rtest_nothn1 WHERE ((new.a >= 30) AND (new.a < 40)) DO INSTEAD NOTHING; rtest_nothn2|rtest_nothn_r3|CREATE RULE rtest_nothn_r3 AS - ON INSERT TO rtest_nothn2 + ON INSERT TO public.rtest_nothn2 WHERE (new.a >= 100) DO INSTEAD INSERT INTO rtest_nothn3 (a, b) VALUES (new.a, new.b); rtest_nothn2|rtest_nothn_r4|CREATE RULE rtest_nothn_r4 AS - ON INSERT TO rtest_nothn2 DO INSTEAD NOTHING; + ON INSERT TO public.rtest_nothn2 DO INSTEAD NOTHING; rtest_order1|rtest_order_r1|CREATE RULE rtest_order_r1 AS - ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) + ON INSERT TO public.rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::regclass), 'rule 1 - this should run 1st'::text); rtest_order1|rtest_order_r2|CREATE RULE rtest_order_r2 AS - ON INSERT TO rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) + ON INSERT TO public.rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::regclass), 'rule 2 - this should run 2nd'::text); rtest_order1|rtest_order_r3|CREATE RULE rtest_order_r3 AS - ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) + ON INSERT TO public.rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::regclass), 'rule 3 - this should run 3rd'::text); rtest_order1|rtest_order_r4|CREATE RULE rtest_order_r4 AS - ON INSERT TO rtest_order1 + ON INSERT TO public.rtest_order1 WHERE (new.a < 100) DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::regclass), 'rule 4 - this should run 4th'::text); rtest_person|rtest_pers_del|CREATE RULE rtest_pers_del AS - ON DELETE TO rtest_person DO DELETE FROM rtest_admin + ON DELETE TO public.rtest_person DO DELETE FROM rtest_admin WHERE (rtest_admin.pname = old.pname); rtest_person|rtest_pers_upd|CREATE RULE rtest_pers_upd AS - ON UPDATE TO rtest_person DO UPDATE rtest_admin SET pname = new.pname + ON UPDATE TO public.rtest_person DO UPDATE rtest_admin SET pname = new.pname WHERE (rtest_admin.pname = old.pname); rtest_system|rtest_sys_del|CREATE RULE rtest_sys_del AS - ON DELETE TO rtest_system DO ( DELETE FROM rtest_interface + ON DELETE TO public.rtest_system DO ( DELETE FROM rtest_interface WHERE (rtest_interface.sysname = old.sysname); DELETE FROM rtest_admin WHERE (rtest_admin.sysname = old.sysname); ); rtest_system|rtest_sys_upd|CREATE RULE rtest_sys_upd AS - ON UPDATE TO rtest_system DO ( UPDATE rtest_interface SET sysname = new.sysname + ON UPDATE TO public.rtest_system DO ( UPDATE rtest_interface SET sysname = new.sysname WHERE (rtest_interface.sysname = old.sysname); UPDATE rtest_admin SET sysname = new.sysname WHERE (rtest_admin.sysname = old.sysname); ); rtest_t4|rtest_t4_ins1|CREATE RULE rtest_t4_ins1 AS - ON INSERT TO rtest_t4 + ON INSERT TO public.rtest_t4 WHERE ((new.a >= 10) AND (new.a < 20)) DO INSTEAD INSERT INTO rtest_t5 (a, b) VALUES (new.a, new.b); rtest_t4|rtest_t4_ins2|CREATE RULE rtest_t4_ins2 AS - ON INSERT TO rtest_t4 + ON INSERT TO public.rtest_t4 WHERE ((new.a >= 20) AND (new.a < 30)) DO INSERT INTO rtest_t6 (a, b) VALUES (new.a, new.b); rtest_t5|rtest_t5_ins|CREATE RULE rtest_t5_ins AS - ON INSERT TO rtest_t5 + ON INSERT TO public.rtest_t5 WHERE (new.a > 15) DO INSERT INTO rtest_t7 (a, b) VALUES (new.a, new.b); rtest_t6|rtest_t6_ins|CREATE RULE rtest_t6_ins AS - ON INSERT TO rtest_t6 + ON INSERT TO public.rtest_t6 WHERE (new.a > 25) DO INSTEAD INSERT INTO rtest_t8 (a, b) VALUES (new.a, new.b); rtest_v1|rtest_v1_del|CREATE RULE rtest_v1_del AS - ON DELETE TO rtest_v1 DO INSTEAD DELETE FROM rtest_t1 + ON DELETE TO public.rtest_v1 DO INSTEAD DELETE FROM rtest_t1 WHERE (rtest_t1.a = old.a); rtest_v1|rtest_v1_ins|CREATE RULE rtest_v1_ins AS - ON INSERT TO rtest_v1 DO INSTEAD INSERT INTO rtest_t1 (a, b) + ON INSERT TO public.rtest_v1 DO INSTEAD INSERT INTO rtest_t1 (a, b) VALUES (new.a, new.b); rtest_v1|rtest_v1_upd|CREATE RULE rtest_v1_upd AS - ON UPDATE TO rtest_v1 DO INSTEAD UPDATE rtest_t1 SET a = new.a, b = new.b + ON UPDATE TO public.rtest_v1 DO INSTEAD UPDATE rtest_t1 SET a = new.a, b = new.b WHERE (rtest_t1.a = old.a); shoelace|shoelace_del|CREATE RULE shoelace_del AS - ON DELETE TO shoelace DO INSTEAD DELETE FROM shoelace_data + ON DELETE TO public.shoelace DO INSTEAD DELETE FROM shoelace_data WHERE (shoelace_data.sl_name = old.sl_name); shoelace|shoelace_ins|CREATE RULE shoelace_ins AS - ON INSERT TO shoelace DO INSTEAD INSERT INTO shoelace_data (sl_name, sl_avail, sl_color, sl_len, sl_unit) + ON INSERT TO public.shoelace DO INSTEAD INSERT INTO shoelace_data (sl_name, sl_avail, sl_color, sl_len, sl_unit) VALUES (new.sl_name, new.sl_avail, new.sl_color, new.sl_len, new.sl_unit); shoelace|shoelace_upd|CREATE RULE shoelace_upd AS - ON UPDATE TO shoelace DO INSTEAD UPDATE shoelace_data SET sl_name = new.sl_name, sl_avail = new.sl_avail, sl_color = new.sl_color, sl_len = new.sl_len, sl_unit = new.sl_unit + ON UPDATE TO public.shoelace DO INSTEAD UPDATE shoelace_data SET sl_name = new.sl_name, sl_avail = new.sl_avail, sl_color = new.sl_color, sl_len = new.sl_len, sl_unit = new.sl_unit WHERE (shoelace_data.sl_name = old.sl_name); shoelace_data|log_shoelace|CREATE RULE log_shoelace AS - ON UPDATE TO shoelace_data + ON UPDATE TO public.shoelace_data WHERE (new.sl_avail <> old.sl_avail) DO INSERT INTO shoelace_log (sl_name, sl_avail, log_who, log_when) VALUES (new.sl_name, new.sl_avail, 'Al Bundy'::name, 'Thu Jan 01 00:00:00 1970'::timestamp without time zone); shoelace_ok|shoelace_ok_ins|CREATE RULE shoelace_ok_ins AS - ON INSERT TO shoelace_ok DO INSTEAD UPDATE shoelace SET sl_avail = (shoelace.sl_avail + new.ok_quant) + ON INSERT TO public.shoelace_ok DO INSTEAD UPDATE shoelace SET sl_avail = (shoelace.sl_avail + new.ok_quant) WHERE (shoelace.sl_name = new.ok_name); -- restore normal output mode \a\t @@ -2961,7 +2961,7 @@ SELECT definition FROM pg_rules WHERE tablename = 'hats' ORDER BY rulename; definition --------------------------------------------------------------------------------------------- CREATE RULE hat_nosert AS + - ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + + ON INSERT TO public.hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name COLLATE "C" bpchar_pattern_ops)+ WHERE (hat_color = 'green'::bpchar) DO NOTHING + RETURNING hat_data.hat_name, + @@ -2986,7 +2986,7 @@ SELECT tablename, rulename, definition FROM pg_rules tablename | rulename | definition -----------+------------+--------------------------------------------------------------------------------------------- hats | hat_nosert | CREATE RULE hat_nosert AS + - | | ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + + | | ON INSERT TO public.hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + | | VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name COLLATE "C" bpchar_pattern_ops)+ | | WHERE (hat_color = 'green'::bpchar) DO NOTHING + | | RETURNING hat_data.hat_name, + @@ -3004,12 +3004,12 @@ CREATE RULE hat_nosert_all AS ON INSERT TO hats DO NOTHING RETURNING *; SELECT definition FROM pg_rules WHERE tablename = 'hats' ORDER BY rulename; - definition ------------------------------------------------------------------------------- - CREATE RULE hat_nosert_all AS + - ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color)+ - VALUES (new.hat_name, new.hat_color) ON CONFLICT DO NOTHING + - RETURNING hat_data.hat_name, + + definition +------------------------------------------------------------------------------------- + CREATE RULE hat_nosert_all AS + + ON INSERT TO public.hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color)+ + VALUES (new.hat_name, new.hat_color) ON CONFLICT DO NOTHING + + RETURNING hat_data.hat_name, + hat_data.hat_color; (1 row) @@ -3036,7 +3036,7 @@ SELECT definition FROM pg_rules WHERE tablename = 'hats' ORDER BY rulename; definition ----------------------------------------------------------------------------------------------------------------------------------------- CREATE RULE hat_upsert AS + - ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + + ON INSERT TO public.hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name) DO UPDATE SET hat_name = hat_data.hat_name, hat_color = excluded.hat_color+ WHERE ((excluded.hat_color <> 'forbidden'::bpchar) AND (hat_data.* <> excluded.*)) + RETURNING hat_data.hat_name, + @@ -3084,7 +3084,7 @@ SELECT tablename, rulename, definition FROM pg_rules tablename | rulename | definition -----------+------------+----------------------------------------------------------------------------------------------------------------------------------------- hats | hat_upsert | CREATE RULE hat_upsert AS + - | | ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + + | | ON INSERT TO public.hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) + | | VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name) DO UPDATE SET hat_name = hat_data.hat_name, hat_color = excluded.hat_color+ | | WHERE ((excluded.hat_color <> 'forbidden'::bpchar) AND (hat_data.* <> excluded.*)) + | | RETURNING hat_data.hat_name, + diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out index e7b4b31afc2..ce8fa211a59 100644 --- a/src/test/regress/expected/triggers.out +++ b/src/test/regress/expected/triggers.out @@ -431,9 +431,9 @@ SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table' (1 row) SELECT pg_get_triggerdef(oid, false) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a'; - pg_get_triggerdef ----------------------------------------------------------------------------------------------------------------------------------------------- - CREATE TRIGGER modified_a BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN ((old.a <> new.a)) EXECUTE PROCEDURE trigger_func('modified_a') + pg_get_triggerdef +----------------------------------------------------------------------------------------------------------------------------------------------------- + CREATE TRIGGER modified_a BEFORE UPDATE OF a ON public.main_table FOR EACH ROW WHEN ((old.a <> new.a)) EXECUTE PROCEDURE trigger_func('modified_a') (1 row) SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_any'; @@ -461,9 +461,9 @@ FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func('before_upd_a_stmt'); CREATE TRIGGER after_upd_b_stmt_trig AFTER UPDATE OF b ON main_table FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func('after_upd_b_stmt'); SELECT pg_get_triggerdef(oid) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'after_upd_a_b_row_trig'; - pg_get_triggerdef -------------------------------------------------------------------------------------------------------------------------------------------- - CREATE TRIGGER after_upd_a_b_row_trig AFTER UPDATE OF a, b ON main_table FOR EACH ROW EXECUTE PROCEDURE trigger_func('after_upd_a_b_row') + pg_get_triggerdef +-------------------------------------------------------------------------------------------------------------------------------------------------- + CREATE TRIGGER after_upd_a_b_row_trig AFTER UPDATE OF a, b ON public.main_table FOR EACH ROW EXECUTE PROCEDURE trigger_func('after_upd_a_b_row') (1 row) UPDATE main_table SET a = 50; |