Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YZUWU-0003Ut-L1 for pgsql-bugs@arkaria.postgresql.org; Sun, 22 Mar 2015 01:17:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YZUWT-0005cK-V4 for pgsql-bugs@arkaria.postgresql.org; Sun, 22 Mar 2015 01:17:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YZUWS-0005cD-VD for pgsql-bugs@postgresql.org; Sun, 22 Mar 2015 01:17:49 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YZUWO-0005ai-3U for pgsql-bugs@postgresql.org; Sun, 22 Mar 2015 01:17:47 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1YZUWK-0007o7-6u; Sat, 21 Mar 2015 21:17:40 -0400 Date: Sat, 21 Mar 2015 21:17:40 -0400 From: Bruce Momjian To: Michael Paquier Cc: Tom Lane , Flavio Henrique Araque Gurgel , pgsql-bugs@postgresql.org, osalm@mirakl.com Subject: Re: ALTER TABLE documentation or parser bug Message-ID: <20150322011740.GB10795@momjian.us> References: <547F462E.8090001@gmail.com> <19734.1417628674@sss.pgh.pa.us> <20150321015254.GC13192@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IrhDeMKUP4DT/M7F" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --IrhDeMKUP4DT/M7F Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Mar 21, 2015 at 04:27:45PM +0900, Michael Paquier wrote: > On Sat, Mar 21, 2015 at 10:52 AM, Bruce Momjian wrote: > > Rather than fixing the docs, I implemented the feature --- patch > > attached. > > A regression test would be welcome, in alter_table for example. OK, regression test added in the attached patch. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --IrhDeMKUP4DT/M7F Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="alter.diff" diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c new file mode 100644 index 4147457..ad81995 *** a/src/backend/commands/tablecmds.c --- b/src/backend/commands/tablecmds.c *************** RenameConstraint(RenameStmt *stmt) *** 2496,2504 **** { /* lock level taken here should match rename_constraint_internal */ relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, ! false, false, RangeVarCallbackForRenameAttribute, NULL); } return --- 2496,2511 ---- { /* lock level taken here should match rename_constraint_internal */ relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, ! stmt->missing_ok, false, RangeVarCallbackForRenameAttribute, NULL); + if (!OidIsValid(relid)) + { + ereport(NOTICE, + (errmsg("relation \"%s\" does not exist, skipping", + stmt->relation->relname))); + return InvalidObjectAddress; + } } return diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y new file mode 100644 index 82405b9..4dc9d7f *** a/src/backend/parser/gram.y --- b/src/backend/parser/gram.y *************** RenameStmt: ALTER AGGREGATE func_name ag *** 7692,7697 **** --- 7692,7708 ---- n->relation = $3; n->subname = $6; n->newname = $8; + n->missing_ok = false; + $$ = (Node *)n; + } + | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name + { + RenameStmt *n = makeNode(RenameStmt); + n->renameType = OBJECT_TABCONSTRAINT; + n->relation = $5; + n->subname = $8; + n->newname = $10; + n->missing_ok = true; $$ = (Node *)n; } | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out new file mode 100644 index 51db1b6..6a31df7 *** a/src/test/regress/expected/alter_table.out --- b/src/test/regress/expected/alter_table.out *************** Inherits: constraint_rename_test *** 289,294 **** --- 289,296 ---- DROP TABLE constraint_rename_test2; DROP TABLE constraint_rename_test; + ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; -- ok + NOTICE: relation "constraint_not_exist" does not exist, skipping ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a); NOTICE: relation "constraint_rename_test" does not exist, skipping -- FOREIGN KEY CONSTRAINT adding TEST diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql new file mode 100644 index d0d29ee..b5ee7b0 *** a/src/test/regress/sql/alter_table.sql --- b/src/test/regress/sql/alter_table.sql *************** ALTER TABLE constraint_rename_test RENAM *** 228,233 **** --- 228,234 ---- \d constraint_rename_test2 DROP TABLE constraint_rename_test2; DROP TABLE constraint_rename_test; + ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; -- ok ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a); -- FOREIGN KEY CONSTRAINT adding TEST --IrhDeMKUP4DT/M7F Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --IrhDeMKUP4DT/M7F--