Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d8198b

Browse files
committed
Add support for ALTER TABLE IF EXISTS ... RENAME CONSTRAINT
Also add regression test. Previously this was documented to work, butdidn't.
1 parentfeeb526 commit1d8198b

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2497,9 +2497,16 @@ RenameConstraint(RenameStmt *stmt)
24972497
{
24982498
/* lock level taken here should match rename_constraint_internal */
24992499
relid=RangeVarGetRelidExtended(stmt->relation,AccessExclusiveLock,
2500-
false, false,
2500+
stmt->missing_ok, false,
25012501
RangeVarCallbackForRenameAttribute,
25022502
NULL);
2503+
if (!OidIsValid(relid))
2504+
{
2505+
ereport(NOTICE,
2506+
(errmsg("relation \"%s\" does not exist, skipping",
2507+
stmt->relation->relname)));
2508+
returnInvalidObjectAddress;
2509+
}
25032510
}
25042511

25052512
return

‎src/backend/parser/gram.y

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7706,6 +7706,17 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
77067706
n->relation =$3;
77077707
n->subname =$6;
77087708
n->newname =$8;
7709+
n->missing_ok =false;
7710+
$$ = (Node *)n;
7711+
}
7712+
|ALTERTABLEIF_PEXISTSrelation_exprRENAMECONSTRAINTnameTOname
7713+
{
7714+
RenameStmt *n = makeNode(RenameStmt);
7715+
n->renameType = OBJECT_TABCONSTRAINT;
7716+
n->relation =$5;
7717+
n->subname =$8;
7718+
n->newname =$10;
7719+
n->missing_ok =true;
77097720
$$ = (Node *)n;
77107721
}
77117722
|ALTERFOREIGNTABLErelation_exprRENAMEopt_columnnameTOname

‎src/test/regress/expected/alter_table.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ Inherits: constraint_rename_test
289289

290290
DROP TABLE constraint_rename_test2;
291291
DROP TABLE constraint_rename_test;
292+
ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; -- ok
293+
NOTICE: relation "constraint_not_exist" does not exist, skipping
292294
ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
293295
NOTICE: relation "constraint_rename_test" does not exist, skipping
294296
-- FOREIGN KEY CONSTRAINT adding TEST

‎src/test/regress/sql/alter_table.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ ALTER TABLE constraint_rename_test RENAME CONSTRAINT con3 TO con3foo; -- ok
228228
\d constraint_rename_test2
229229
DROPTABLE constraint_rename_test2;
230230
DROPTABLE constraint_rename_test;
231+
ALTERTABLE IF EXISTS constraint_not_exist RENAMECONSTRAINT con3 TO con3foo;-- ok
231232
ALTERTABLE IF EXISTS constraint_rename_test ADDCONSTRAINT con4 UNIQUE (a);
232233

233234
-- FOREIGN KEY CONSTRAINT adding TEST

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp