Re: using vars in ddl in procedure call

From: salah jubeh <s_jubeh(at)yahoo(dot)com>
To: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: using vars in ddl in procedure call
Date: 2012-08-29 15:12:23
Message-ID: 1346253143.28160.YahooMailNeo@web122205.mail.ne1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,
you need to use execute command 

i.e.

execute 'alter table ........ ' || newcol || ';'

Regards

________________________________
From: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Sent: Wednesday, August 29, 2012 4:56 PM
Subject: [GENERAL] using vars in ddl in procedure call


Hi:
 
v9.0.1 on linux.
 
Trying (failing) a test to see if I can run ddl in a procedure where elements of the ddl are vars.  Consider...
 
create or replace function newcol (text) returns integer as $$
declare
  newcol alias for $1;
begin
 
  alter table target add column newcol text;
 
return(0);
 
end;
$$ language plpgsql;
 
This successfully adds a column called "newcol" instead of what I passed it as an arg.
 
Any suggestions on how to make this work?
 
Thanks !

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-08-29 15:18:06 Re: using vars in ddl in procedure call
Previous Message Merlin Moncure 2012-08-29 15:08:21 Re: String comparision in PostgreSQL