Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cW2jR-0006Wo-Dm for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2017 15:10:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cW2jQ-0003xZ-Li for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2017 15:10:00 +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 1cW2hu-0000yN-6g for pgsql-hackers@postgresql.org; Tue, 24 Jan 2017 15:08:26 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cW2hr-0001eV-9g for pgsql-hackers@postgresql.org; Tue, 24 Jan 2017 15:08:24 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 76B5E2082F; Tue, 24 Jan 2017 10:08:22 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Tue, 24 Jan 2017 10:08:22 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=B8AF1hVUv82EQF AsruJ3GI+J9TY=; b=KYxxi74Cnaq1Q30GafcmTQpilRDsxnE3wloqJfuselhg+N Fg6yvLK4nmLXwKpHOQSRrWDfaEHsTddhlXZi5qMS0/KFgO47KWZZ9/uMVe4Dg3IT b3Rm4iDtV0k5Q6e3ipmFhqz+9U3bCqYZWtZupUEFHfI2Ley8X8oD9a5vBNmhg= X-ME-Sender: X-Sasl-enc: YxBjJvkiltbwc3x5plKpAODAoFb1RJS8fA8+obpCZVce 1485270502 Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 3DFAC24428; Tue, 24 Jan 2017 10:08:22 -0500 (EST) Subject: Re: [COMMITTERS] pgsql: Add pg_sequence system catalog To: Stephen Frost References: <20170119160305.GS18360@tamriel.snowman.net> Cc: pgsql-hackers@postgresql.org From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <1b722fdc-7f69-9033-2bed-34e318d61a74@2ndquadrant.com> Date: Tue, 24 Jan 2017 10:08:21 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <20170119160305.GS18360@tamriel.snowman.net> Content-Type: multipart/mixed; boundary="------------2C647D954D59A34BF9262EFF" X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------2C647D954D59A34BF9262EFF Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 1/19/17 11:03 AM, Stephen Frost wrote: > I'd suggest using our usual approach in pg_dump, which is matching based > on the OID, like so: > > WHERE c.oid = '%u'::oid > > The OID is in: tbinfo->dobj.catId.oid > > Also, you should move the selectSourceSchema() into the per-version > branches and set it to 'pg_catalog' for PG10 and up, which would allow > you to avoid having to qualify the table names, et al. Does the attached patch look correct to you? -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------2C647D954D59A34BF9262EFF Content-Type: text/x-patch; name="0001-pg_dump-Fix-some-schema-issues-when-dumping-sequence.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-pg_dump-Fix-some-schema-issues-when-dumping-sequence.pa"; filename*1="tch" From 96820dd460e9fe842a608d99e7a1da2f8b9ce67d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 24 Jan 2017 10:03:25 -0500 Subject: [PATCH] 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 --- src/bin/pg_dump/pg_dump.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index e3cca62bf7..b28b7e42d4 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15873,14 +15873,14 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) PQExpBuffer delqry = 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(bufx, sizeof(bufx), INT64_FORMAT, PG_INT64_MAX); if (fout->remoteVersion >= 100000) { + /* Make sure we are in proper schema */ + selectSourceSchema(fout, "pg_catalog"); + appendPQExpBuffer(query, "SELECT seqstart, seqincrement, " "CASE WHEN seqincrement > 0 AND seqmax = %s THEN NULL " @@ -15894,12 +15894,15 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) "seqcache, seqcycle " "FROM pg_class c " "JOIN pg_sequence s ON (s.seqrelid = c.oid) " - "WHERE relname = ", - bufx, bufm); - appendStringLiteralAH(query, tbinfo->dobj.name, fout); + "WHERE c.oid = '%u'::oid", + bufx, bufm, + tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 80400) { + /* Make sure we are in proper schema */ + selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); + appendPQExpBuffer(query, "SELECT start_value, increment_by, " "CASE WHEN increment_by > 0 AND max_value = %s THEN NULL " @@ -15916,6 +15919,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) } else { + /* Make sure we are in proper schema */ + selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); + appendPQExpBuffer(query, "SELECT 0 AS start_value, increment_by, " "CASE WHEN increment_by > 0 AND max_value = %s THEN NULL " -- 2.11.0 --------------2C647D954D59A34BF9262EFF Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------2C647D954D59A34BF9262EFF--