dbTalk Databases Forums  

Stored procedure and dynamic statements?

comp.databases.postgresql comp.databases.postgresql


Discuss Stored procedure and dynamic statements? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
durumdara
 
Posts: n/a

Default Stored procedure and dynamic statements? - 03-07-2011 , 05:21 AM






Hi!

I want to ask that is pg supports dynamic usage of SQL, or variable as
SQL (or part of SQL) statement?

:tablename = call CreateTempTable;
insert into :tablename ....
drop table :tablename

or (FireBird like cursor handling):

sql = "select * from " || :tablename || " where..."
for select :sql ....
....

Thanks for your help:
dd

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Stored procedure and dynamic statements? - 05-03-2011 , 03:04 AM






durumdara wrote:
Quote:
I want to ask that is pg supports dynamic usage of SQL, or variable as
SQL (or part of SQL) statement?

:tablename = call CreateTempTable;
insert into :tablename ....
drop table :tablename

or (FireBird like cursor handling):

sql = "select * from " || :tablename || " where..."
for select :sql ....
...
SQL itself does not support that, but there are things like that
in psql:

\set varname value
CREATE TABLE :varname (id integer);
INSERT INTO :varname VALUES (1);

Does that help?

Yours,
Laurenz Albe

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.