aboutsummaryrefslogtreecommitdiff
path: root/src/fe_utils/string_utils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-08-17 17:12:21 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-08-17 17:12:21 -0400
commitd73093c4ffefebadd25ea855bd8745f4fcb4462a (patch)
treeaec3c03172f7bd50a1c986fad327c2cf86440391 /src/fe_utils/string_utils.c
parent67b161eae32b0e900f74a2fe0b3f01667ca70850 (diff)
downloadpostgresql-d73093c4ffefebadd25ea855bd8745f4fcb4462a.tar.gz
postgresql-d73093c4ffefebadd25ea855bd8745f4fcb4462a.zip
Ensure schema qualification in pg_restore DISABLE/ENABLE TRIGGER commands.
Previously, this code blindly followed the common coding pattern of passing PQserverVersion(AH->connection) as the server-version parameter of fmtQualifiedId. That works as long as we have a connection; but in pg_restore with text output, we don't. Instead we got a zero from PQserverVersion, which fmtQualifiedId interpreted as "server is too old to have schemas", and so the name went unqualified. That still accidentally managed to work in many cases, which is probably why this ancient bug went undetected for so long. It only became obvious in the wake of the changes to force dump/restore to execute with restricted search_path. In HEAD/v11, let's deal with this by ripping out fmtQualifiedId's server- version behavioral dependency, and just making it schema-qualify all the time. We no longer support pg_dump from servers old enough to need the ability to omit schema name, let alone restoring to them. (Also, the few callers outside pg_dump already didn't work with pre-schema servers.) In older branches, that's not an acceptable solution, so instead just tweak the DISABLE/ENABLE TRIGGER logic to ensure it will schema-qualify its output regardless of server version. Per bug #15338 from Oleg somebody. Back-patch to all supported branches. Discussion: https://postgr.es/m/153452458706.1316.5328079417086507743@wrigleys.postgresql.org
Diffstat (limited to 'src/fe_utils/string_utils.c')
-rw-r--r--src/fe_utils/string_utils.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c
index b47a396af15..af0d9d5173e 100644
--- a/src/fe_utils/string_utils.c
+++ b/src/fe_utils/string_utils.c
@@ -138,8 +138,7 @@ fmtId(const char *rawid)
}
/*
- * fmtQualifiedId - convert a qualified name to the proper format for
- * the source database.
+ * fmtQualifiedId - construct a schema-qualified name, with quoting as needed.
*
* Like fmtId, use the result before calling again.
*
@@ -147,13 +146,13 @@ fmtId(const char *rawid)
* use that buffer until we're finished with calling fmtId().
*/
const char *
-fmtQualifiedId(int remoteVersion, const char *schema, const char *id)
+fmtQualifiedId(const char *schema, const char *id)
{
PQExpBuffer id_return;
PQExpBuffer lcl_pqexp = createPQExpBuffer();
- /* Suppress schema name if fetching from pre-7.3 DB */
- if (remoteVersion >= 70300 && schema && *schema)
+ /* Some callers might fail to provide a schema name */
+ if (schema && *schema)
{
appendPQExpBuffer(lcl_pqexp, "%s.", fmtId(schema));
}