Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2062ab9

Browse files
committed
[PGPRO-5255] fix that ALTER TABLE IF EXISTS ... RENAME TO of not existed table generate ERROR instead of NOTICE
1 parent 6b484c2 commit 2062ab9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

expected/pathman_utility_stmt.out

+7
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,11 @@ SELECT create_hash_partitions('drop_index.test', 'val', 2);
370370
DROP INDEX CONCURRENTLY drop_index.test_0_val_idx;
371371
DROP SCHEMA drop_index CASCADE;
372372
NOTICE: drop cascades to 3 other objects
373+
/*
374+
* Test, that ALTER TABLE IF EXISTS ... RENAME TO of not existed table generate NOTICE instead of ERROR
375+
*/
376+
CREATE SCHEMA rename_nonexistent;
377+
ALTER TABLE IF EXISTS rename_nonexistent.nonexistent_table RENAME TO other_table_name;
378+
NOTICE: relation "nonexistent_table" does not exist, skipping
379+
DROP SCHEMA rename_nonexistent CASCADE;
373380
DROP EXTENSION pg_pathman;

sql/pathman_utility_stmt.sql

+6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ DROP INDEX CONCURRENTLY drop_index.test_0_val_idx;
250250

251251
DROP SCHEMA drop_index CASCADE;
252252

253+
/*
254+
* Test, that ALTER TABLE IF EXISTS ... RENAME TO of not existed table generate NOTICE instead of ERROR
255+
*/
256+
CREATE SCHEMA rename_nonexistent;
257+
ALTER TABLE IF EXISTS rename_nonexistent.nonexistent_table RENAME TO other_table_name;
258+
DROP SCHEMA rename_nonexistent CASCADE;
253259

254260

255261
DROP EXTENSION pg_pathman;

src/utility_stmt_hooking.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ is_pathman_related_table_rename(Node *parsetree,
175175
/* Fetch Oid of this relation */
176176
relation_oid = RangeVarGetRelid(rename_stmt->relation,
177177
AccessShareLock,
178-
false);
178+
rename_stmt->missing_ok);
179+
/* PGPRO-5255: check ALTER TABLE IF EXISTS of non existent table */
180+
if (rename_stmt->missing_ok && relation_oid == InvalidOid)
181+
return false;
179182

180183
/* Assume it's a parent */
181184
if (has_pathman_relation_info(relation_oid))

0 commit comments

Comments
 (0)