Skip to content

Commit 1b1dbb8

Browse files
committed
Fix bug in sequence dumping using new setval function
1 parent 8fb04f8 commit 1b1dbb8

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,12 +1483,16 @@ static int _tocEntryRequired(TocEntry* te, RestoreOptions *ropt)
14831483
}
14841484
}
14851485

1486+
/* Special Case: If 'SEQUENCE SET' and schemaOnly, then not needed */
1487+
if (ropt->schemaOnly && (strcmp(te->desc, "SEQUENCE SET") == 0) )
1488+
return 0;
1489+
14861490
/* Mask it if we only want schema */
14871491
if (ropt->schemaOnly)
14881492
res = res & 1;
14891493

14901494
/* Mask it we only want data */
1491-
if (ropt->dataOnly)
1495+
if (ropt->dataOnly && (strcmp(te->desc, "SEQUENCE SET") != 0) )
14921496
res = res & 2;
14931497

14941498
/* Mask it if we don't have a schema contribition */

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
6262

6363
#define K_VERS_MAJOR 1
6464
#define K_VERS_MINOR 4
65-
#define K_VERS_REV 16
65+
#define K_VERS_REV 17
6666

6767
/* Data block types */
6868
#define BLK_DATA 1

src/bin/pg_dump/pg_dump.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.169 2000/10/10 13:55:28 pjw Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.170 2000/10/13 00:43:31 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -992,6 +992,7 @@ main(int argc, char **argv)
992992
MoveToEnd(g_fout, "INDEX");
993993
MoveToEnd(g_fout, "TRIGGER");
994994
MoveToEnd(g_fout, "RULE");
995+
MoveToEnd(g_fout, "SEQUENCE SET");
995996

996997
if (plainText)
997998
{
@@ -4015,20 +4016,32 @@ dumpSequence(Archive *fout, TableInfo tbinfo)
40154016
resetPQExpBuffer(delqry);
40164017
appendPQExpBuffer(delqry, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes));
40174018

4019+
/*
4020+
* The logic we use for restoring sequences is as follows:
4021+
* - Add a basic CREATE SEQUENCE statement
4022+
* (use last_val for start if called == 'f', else use min_val for start_val).
4023+
* - Add a 'SETVAL(seq, last_val, iscalled)' at restore-time iff we load data
4024+
*/
40184025
resetPQExpBuffer(query);
40194026
appendPQExpBuffer(query,
40204027
"CREATE SEQUENCE %s start %d increment %d maxvalue %d "
40214028
"minvalue %d cache %d %s;\n",
4022-
fmtId(tbinfo.relname, force_quotes), last, incby, maxv, minv, cache,
4029+
fmtId(tbinfo.relname, force_quotes),
4030+
(called == 't') ? minv : last,
4031+
incby, maxv, minv, cache,
40234032
(cycled == 't') ? "cycle" : "");
40244033

4025-
if (called != 'f') {
4026-
appendPQExpBuffer(query, "SELECT nextval ('%s');\n", fmtId(tbinfo.relname, force_quotes));
4027-
}
4028-
40294034
ArchiveEntry(fout, tbinfo.oid, fmtId(tbinfo.relname, force_quotes), "SEQUENCE", NULL,
40304035
query->data, delqry->data, "", tbinfo.usename, NULL, NULL);
40314036

4037+
4038+
resetPQExpBuffer(query);
4039+
appendPQExpBuffer(query, "SELECT setval ('%s', %d, '%c');\n",
4040+
fmtId(tbinfo.relname, force_quotes), last, called);
4041+
4042+
ArchiveEntry(fout, tbinfo.oid, fmtId(tbinfo.relname, force_quotes), "SEQUENCE SET", NULL,
4043+
query->data, "" /* Del */, "", "", NULL, NULL);
4044+
40324045
/* Dump Sequence Comments */
40334046

40344047
resetPQExpBuffer(query);

src/bin/pg_dump/pg_restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ int main(int argc, char **argv)
292292
MoveToEnd(AH, "INDEX");
293293
MoveToEnd(AH, "TRIGGER");
294294
MoveToEnd(AH, "RULE");
295-
MoveToEnd(AH, "ACL");
295+
MoveToEnd(AH, "SEQUENCE SET");
296296
}
297297

298298
/* Database MUST be at start */

0 commit comments

Comments
 (0)