Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1enodW-0005cY-9k for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Feb 2018 16:49:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enodU-00080D-Ps for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Feb 2018 16:49:52 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1enodU-000802-Ga for pgsql-bugs@lists.postgresql.org; Mon, 19 Feb 2018 16:49:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1enodS-0003tC-1r for pgsql-bugs@postgresql.org; Mon, 19 Feb 2018 16:49:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w1JGnjFD016277; Mon, 19 Feb 2018 11:49:45 -0500 From: Tom Lane To: Alexey Bashtanov cc: pgsql-bugs@postgresql.org, Peter Eisentraut Subject: Re: pg_dump sometimes misses sequence parameters In-reply-to: References: Comments: In-reply-to Alexey Bashtanov message dated "Mon, 19 Feb 2018 13:32:56 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16275.1519058985.1@sss.pgh.pa.us> Date: Mon, 19 Feb 2018 11:49:45 -0500 Message-ID: <16276.1519058985@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexey Bashtanov 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 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