Re: using vars in ddl in procedure call - Mailing list pgsql-general

From salah jubeh
Subject Re: using vars in ddl in procedure call
Date
Msg-id 1346253143.28160.YahooMailNeo@web122205.mail.ne1.yahoo.com
Whole thread Raw
In response to using vars in ddl in procedure call  ("Gauthier, Dave" <dave.gauthier@intel.com>)
List pgsql-general
Hello,
you need to use execute command 

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

Regards



From: "Gauthier, Dave" <dave.gauthier@intel.com>
To: "pgsql-general@postgresql.org" <pgsql-general@postgresql.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 !
 


pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: String comparision in PostgreSQL
Next
From: Tom Lane
Date:
Subject: Re: using vars in ddl in procedure call