From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexey Bashtanov <bashtanov@imap.cc>
Cc: pgsql-bugs@postgresql.org, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Subject: Re: pg_dump sometimes misses sequence parameters
Date: Mon, 19 Feb 2018 11:49:45 -0500
Message-ID: <16276.1519058985@sss.pgh.pa.us> (raw)
In-Reply-To: <cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc>
References: <cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc>
Alexey Bashtanov <bashtanov@imap.cc> writes:
> 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.
Ugh.
> 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.
That will only fix it on platforms where long is 64 bits. I think that
converting these strings to integer at all is a dumb idea. It would be
much better to write the first two tests like
if (is_ascending && strcmp(minv, "1") == 0)
minv = NULL;
if (!is_ascending && strcmp(maxv, "-1") == 0)
maxv = NULL;
It's tempting to try to make the remaining tests look similar, but
I'm not quite sure how without writing out the exact decimal values
of the constants, which probably isn't better. I experimented with
stuff like "strcmp(minv, CppAsString2(PG_INT32_MIN))" but that
doesn't quite do what we need.
regards, tom lane
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: tgl@sss.pgh.pa.us, bashtanov@imap.cc, peter.eisentraut@2ndquadrant.com
Subject: Re: pg_dump sometimes misses sequence parameters
In-Reply-To: <16276.1519058985@sss.pgh.pa.us>
References: <cb85a9a5-946b-c7c4-9cf2-6cd6e25d7a33@imap.cc> <16276.1519058985@sss.pgh.pa.us>
* 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