pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Alexey Bashtanov <bashtanov@imap.cc>
To: pgsql-bugs@postgresql.org
Subject: pg_dump sometimes misses sequence parameters
Date: Mon, 19 Feb 2018 13:32:56 +0000
Message-ID: <cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc> (raw )
The bug affects REL_10_STABLE and master branches.
9.4..9.6 are unaffected.
To reproduce:
psql -c 'DROP SEQUENCE IF EXISTS foo'
psql -c 'CREATE SEQUENCE foo INCREMENT BY -1 MINVALUE
-9223372036854775808 MAXVALUE 9223372036854775807'
pg_dump -t foo > tmp
psql -c 'DROP SEQUENCE foo'
psql <tmp
The last psql call fails with "START value (9223372036854775807) cannot
be greater than MAXVALUE (-1)",
as pg_dump does not record MAXVALUE properly.
The reason is atoi is used and those large numbers are interpreted as 0
and -1 respectively.
I'd propose to use atol instead of atoi, please see the patch attached.
Best,
Alexey
Attachments:
pgdump_seq.diff (text/x-patch, 1.4K) download
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
new file mode 100644
index 06bbc50..d9d331e
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
*************** dumpSequence(Archive *fout, TableInfo *t
*** 16914,16936 ****
is_ascending = incby[0] != '-';
! if (is_ascending && atoi(minv) == 1)
minv = NULL;
! if (!is_ascending && atoi(maxv) == -1)
maxv = NULL;
if (strcmp(seqtype, "smallint") == 0)
{
! if (!is_ascending && atoi(minv) == PG_INT16_MIN)
minv = NULL;
! if (is_ascending && atoi(maxv) == PG_INT16_MAX)
maxv = NULL;
}
else if (strcmp(seqtype, "integer") == 0)
{
! if (!is_ascending && atoi(minv) == PG_INT32_MIN)
minv = NULL;
! if (is_ascending && atoi(maxv) == PG_INT32_MAX)
maxv = NULL;
}
else if (strcmp(seqtype, "bigint") == 0)
--- 16914,16936 ----
is_ascending = incby[0] != '-';
! if (is_ascending && atol(minv) == 1)
minv = NULL;
! if (!is_ascending && atol(maxv) == -1)
maxv = NULL;
if (strcmp(seqtype, "smallint") == 0)
{
! if (!is_ascending && atol(minv) == PG_INT16_MIN)
minv = NULL;
! if (is_ascending && atol(maxv) == PG_INT16_MAX)
maxv = NULL;
}
else if (strcmp(seqtype, "integer") == 0)
{
! if (!is_ascending && atol(minv) == PG_INT32_MIN)
minv = NULL;
! if (is_ascending && atol(maxv) == PG_INT32_MAX)
maxv = NULL;
}
else if (strcmp(seqtype, "bigint") == 0)
view thread (4+ messages) latest in thread
Message-ID: <cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc>
Permalink: ../cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc/
Also on: postgresql.org/message-id/cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bashtanov@imap.cc
Subject: Re: pg_dump sometimes misses sequence parameters
In-Reply-To: <cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc>
References: <cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox