Question

I wonder if it is possible to rename Postgres table without cascading type change to dependent objects? For example,

create table test_1(id int);
create function test_1_funct (param test_1[]) returns void as $body$
begin
    return;
end 
$body$
language plpgsql;
alter table test_1 rename to test_2 ; 
 -- function test_1_funct signature silently changed, 
 -- so it now accepts test_2[]. 

I want to emulate behaviour similar to what Oracle would do - mark function invalid, let me create table with the old name, and recompile the function on demand . As it is, it doesn't let me drop table test_2.

Was it helpful?

Solution

It isn't. Not should it be. Tables resolve to an oid that represents their relation.

SELECT 'test_1'::regclass::oid;
SELECT oid, relname FROM pg_catalog.pg_class WHERE relname = 'test_1';
SELECT oid, relname FROM pg_catalog.pg_class WHERE oid = 'test_1'::regclass::oid;

Changing their "name" is essentially a catalog update on relname. How would what you're talking about look anyway: what would happen if you called test_1_funct after the rename? What type would it expect?

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top