2

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.

2

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?

  • Ideally I'd like to get a runtime error. It'd save lots of time while doing , for instance , existing table partitioning... – a1ex07 Nov 23 '17 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.