mirror of
https://github.com/postgres/postgres.git
synced 2025-05-15 19:15:29 +03:00
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>
This commit is contained in:
parent
ba005f193d
commit
da4d1c0c15
@ -15873,14 +15873,14 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
|
|||||||
PQExpBuffer delqry = createPQExpBuffer();
|
PQExpBuffer delqry = createPQExpBuffer();
|
||||||
PQExpBuffer labelq = 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(bufm, sizeof(bufm), INT64_FORMAT, PG_INT64_MIN);
|
||||||
snprintf(bufx, sizeof(bufx), INT64_FORMAT, PG_INT64_MAX);
|
snprintf(bufx, sizeof(bufx), INT64_FORMAT, PG_INT64_MAX);
|
||||||
|
|
||||||
if (fout->remoteVersion >= 100000)
|
if (fout->remoteVersion >= 100000)
|
||||||
{
|
{
|
||||||
|
/* Make sure we are in proper schema */
|
||||||
|
selectSourceSchema(fout, "pg_catalog");
|
||||||
|
|
||||||
appendPQExpBuffer(query,
|
appendPQExpBuffer(query,
|
||||||
"SELECT seqstart, seqincrement, "
|
"SELECT seqstart, seqincrement, "
|
||||||
"CASE WHEN seqincrement > 0 AND seqmax = %s THEN NULL "
|
"CASE WHEN seqincrement > 0 AND seqmax = %s THEN NULL "
|
||||||
@ -15894,12 +15894,20 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
|
|||||||
"seqcache, seqcycle "
|
"seqcache, seqcycle "
|
||||||
"FROM pg_class c "
|
"FROM pg_class c "
|
||||||
"JOIN pg_sequence s ON (s.seqrelid = c.oid) "
|
"JOIN pg_sequence s ON (s.seqrelid = c.oid) "
|
||||||
"WHERE relname = ",
|
"WHERE c.oid = '%u'::oid",
|
||||||
bufx, bufm);
|
bufx, bufm,
|
||||||
appendStringLiteralAH(query, tbinfo->dobj.name, fout);
|
tbinfo->dobj.catId.oid);
|
||||||
}
|
}
|
||||||
else if (fout->remoteVersion >= 80400)
|
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,
|
appendPQExpBuffer(query,
|
||||||
"SELECT start_value, increment_by, "
|
"SELECT start_value, increment_by, "
|
||||||
"CASE WHEN increment_by > 0 AND max_value = %s THEN NULL "
|
"CASE WHEN increment_by > 0 AND max_value = %s THEN NULL "
|
||||||
@ -15916,6 +15924,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Make sure we are in proper schema */
|
||||||
|
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
|
||||||
|
|
||||||
appendPQExpBuffer(query,
|
appendPQExpBuffer(query,
|
||||||
"SELECT 0 AS start_value, increment_by, "
|
"SELECT 0 AS start_value, increment_by, "
|
||||||
"CASE WHEN increment_by > 0 AND max_value = %s THEN NULL "
|
"CASE WHEN increment_by > 0 AND max_value = %s THEN NULL "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user