By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Selection in pgsql using dynamic tables.

P: 1
Hi,
I have a function(stored procedure) in the database. I need to pass the table name which is a variable. How do i do that?
Example :
I have 1st table : table name - cities
location | city
(text) | (text)
---------------------
1 bangalore
2 mangalore

Now from this table depending upon location 1 or 2, I need to select the particular city and each city is another table for me which contains different parameters like, population, num of educated ppl, and num of schools.
So, from this selected city, I need to select data from population column.

This needs to be done in stored procedures in pgsql and so, I would need a single query for this. If any one knows, please help me out.
Nov 23 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 700
Hi,
I have a function(stored procedure) in the database. I need to pass the table name which is a variable. How do i do that?
Example :
I have 1st table : table name - cities
location | city
(text) | (text)
---------------------
1 bangalore
2 mangalore

Now from this table depending upon location 1 or 2, I need to select the particular city and each city is another table for me which contains different parameters like, population, num of educated ppl, and num of schools.
So, from this selected city, I need to select data from population column.

This needs to be done in stored procedures in pgsql and so, I would need a single query for this. If any one knows, please help me out.
My english isn't good but aren't you looking for a dynamic queries in plpgsql (execute command see here
http://www.postgresql.org/docs/curre...-EXECUTING-DYN
Nov 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.