File tree Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Original file line number Diff line number Diff 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+ return InvalidObjectAddress ;
2509+ }
25032510 }
25042511
25052512 return
Original file line number Diff line number Diff 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+ | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
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 | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
Original file line number Diff line number Diff line change @@ -289,6 +289,8 @@ Inherits: constraint_rename_test
289289
290290DROP TABLE constraint_rename_test2;
291291DROP 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
292294ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
293295NOTICE: relation "constraint_rename_test" does not exist, skipping
294296-- FOREIGN KEY CONSTRAINT adding TEST
Original file line number Diff line number Diff line change @@ -228,6 +228,7 @@ ALTER TABLE constraint_rename_test RENAME CONSTRAINT con3 TO con3foo; -- ok
228228\d constraint_rename_test2
229229DROP TABLE constraint_rename_test2;
230230DROP TABLE constraint_rename_test;
231+ ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; -- ok
231232ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
232233
233234-- FOREIGN KEY CONSTRAINT adding TEST
You can’t perform that action at this time.
0 commit comments