Skip to content

Commit da4d1c0

Browse files
committed
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>
1 parent ba005f1 commit da4d1c0

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15873,14 +15873,14 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1587315873
PQExpBuffer delqry = createPQExpBuffer();
1587415874
PQExpBuffer labelq = createPQExpBuffer();
1587515875

15876-
/* Make sure we are in proper schema */
15877-
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
15878-
1587915876
snprintf(bufm, sizeof(bufm), INT64_FORMAT, PG_INT64_MIN);
1588015877
snprintf(bufx, sizeof(bufx), INT64_FORMAT, PG_INT64_MAX);
1588115878

1588215879
if (fout->remoteVersion >= 100000)
1588315880
{
15881+
/* Make sure we are in proper schema */
15882+
selectSourceSchema(fout, "pg_catalog");
15883+
1588415884
appendPQExpBuffer(query,
1588515885
"SELECT seqstart, seqincrement, "
1588615886
"CASE WHEN seqincrement > 0 AND seqmax = %s THEN NULL "
@@ -15894,12 +15894,20 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1589415894
"seqcache, seqcycle "
1589515895
"FROM pg_class c "
1589615896
"JOIN pg_sequence s ON (s.seqrelid = c.oid) "
15897-
"WHERE relname = ",
15898-
bufx, bufm);
15899-
appendStringLiteralAH(query, tbinfo->dobj.name, fout);
15897+
"WHERE c.oid = '%u'::oid",
15898+
bufx, bufm,
15899+
tbinfo->dobj.catId.oid);
1590015900
}
1590115901
else if (fout->remoteVersion >= 80400)
1590215902
{
15903+
/*
15904+
* Before PostgreSQL 10, sequence metadata is in the sequence itself,
15905+
* so switch to the sequence's schema instead of pg_catalog.
15906+
*/
15907+
15908+
/* Make sure we are in proper schema */
15909+
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
15910+
1590315911
appendPQExpBuffer(query,
1590415912
"SELECT start_value, increment_by, "
1590515913
"CASE WHEN increment_by > 0 AND max_value = %s THEN NULL "
@@ -15916,6 +15924,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1591615924
}
1591715925
else
1591815926
{
15927+
/* Make sure we are in proper schema */
15928+
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
15929+
1591915930
appendPQExpBuffer(query,
1592015931
"SELECT 0 AS start_value, increment_by, "
1592115932
"CASE WHEN increment_by > 0 AND max_value = %s THEN NULL "

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy