File tree 4 files changed +22
-1
lines changed
4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -2497,9 +2497,16 @@ RenameConstraint(RenameStmt *stmt)
2497
2497
{
2498
2498
/* lock level taken here should match rename_constraint_internal */
2499
2499
relid = RangeVarGetRelidExtended (stmt -> relation , AccessExclusiveLock ,
2500
- false , false,
2500
+ stmt -> missing_ok , false,
2501
2501
RangeVarCallbackForRenameAttribute ,
2502
2502
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
+ }
2503
2510
}
2504
2511
2505
2512
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
7706
7706
n->relation = $3 ;
7707
7707
n->subname = $6 ;
7708
7708
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 ;
7709
7720
$$ = (Node *)n;
7710
7721
}
7711
7722
| 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
289
289
290
290
DROP TABLE constraint_rename_test2;
291
291
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
292
294
ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
293
295
NOTICE: relation "constraint_rename_test" does not exist, skipping
294
296
-- 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
228
228
\d constraint_rename_test2
229
229
DROP TABLE constraint_rename_test2;
230
230
DROP TABLE constraint_rename_test;
231
+ ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; -- ok
231
232
ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
232
233
233
234
-- FOREIGN KEY CONSTRAINT adding TEST
You can’t perform that action at this time.
0 commit comments