diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2017-01-24 17:03:56 -0500 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2017-01-24 17:19:55 -0500 |
commit | da4d1c0c15ab9afdfeee8bad9a1a9989b6bd59b5 (patch) | |
tree | 2c15c4b603e0875b30840ee127e9d6de0ddd2f43 | |
parent | ba005f193d88a8404e81db3df223cf689d64d75e (diff) | |
download | postgresql-da4d1c0c15ab9afdfeee8bad9a1a9989b6bd59b5.tar.gz postgresql-da4d1c0c15ab9afdfeee8bad9a1a9989b6bd59b5.zip |
pg_dump: Fix some schema issues when dumping sequences
In the new code for selecting sequence data from pg_sequence, set the
schema to pg_catalog instead of the sequences own schema, and refer to
the sequence by OID instead of name, which was missing a schema
qualification.
Reported-by: Stephen Frost <sfrost@snowman.net>
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index e3cca62bf72..a6de9d7bc21 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15873,14 +15873,14 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) PQExpBuffer delqry = createPQExpBuffer(); PQExpBuffer labelq = createPQExpBuffer(); - /* Make sure we are in proper schema */ - selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); - snprintf(bufm, sizeof(bufm), INT64_FORMAT, PG_INT64_MIN); snprintf(bufx, sizeof(bufx), INT64_FORMAT, PG_INT64_MAX); if (fout->remoteVersion >= 100000) { + /* Make sure we are in proper schema */ + selectSourceSchema(fout, "pg_catalog"); + appendPQExpBuffer(query, "SELECT seqstart, seqincrement, " "CASE WHEN seqincrement > 0 AND seqmax = %s THEN NULL " @@ -15894,12 +15894,20 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) "seqcache, seqcycle " "FROM pg_class c " "JOIN pg_sequence s ON (s.seqrelid = c.oid) " - "WHERE relname = ", - bufx, bufm); - appendStringLiteralAH(query, tbinfo->dobj.name, fout); + "WHERE c.oid = '%u'::oid", + bufx, bufm, + 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. + */ + + /* Make sure we are in proper schema */ + selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); + appendPQExpBuffer(query, "SELECT start_value, increment_by, " "CASE WHEN increment_by > 0 AND max_value = %s THEN NULL " @@ -15916,6 +15924,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) } else { + /* Make sure we are in proper schema */ + selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); + appendPQExpBuffer(query, "SELECT 0 AS start_value, increment_by, " "CASE WHEN increment_by > 0 AND max_value = %s THEN NULL " |