Skip to content

Commit

Permalink
Fix error on rename table to same name
Browse files Browse the repository at this point in the history
  • Loading branch information
seancolsen committed Jul 21, 2024
1 parent f66bc48 commit da89d22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,10 @@ Args:
new_tab_name: unquoted, unqualified new table name
*/
BEGIN
IF old_tab_name = new_tab_name THEN
-- Return early if the names are the same. This avoids an error from Postgres.
RETURN;
END IF;
EXECUTE format('ALTER TABLE %I.%I RENAME TO %I', sch_name, old_tab_name, new_tab_name);
END;
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;
Expand Down
13 changes: 13 additions & 0 deletions db/sql/test_00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,19 @@ END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_rename_table_with_same_name() RETURNS SETOF TEXT AS $$
BEGIN
PERFORM __setup_alter_table();
PERFORM msar.rename_table(
sch_name =>'public',
old_tab_name => 'alter_this_table',
new_tab_name => 'alter_this_table'
);
RETURN NEXT has_table('alter_this_table');
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_rename_table_using_oid() RETURNS SETOF TEXT AS $$
BEGIN
PERFORM __setup_alter_table();
Expand Down

0 comments on commit da89d22

Please sign in to comment.