Selection in pgsql using dynamic tables.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shoma
    New Member
    • Nov 2007
    • 1

    Selection in pgsql using dynamic tables.

    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.
    Last edited by Shoma; Nov 23 '07, 06:23 PM. Reason: Wording it better
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Originally posted by Shoma
    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
    41.5. Basic Statements # 41.5.1. Assignment 41.5.2. Executing SQL Commands 41.5.3. Executing a Command with a Single-Row Result 41.5.4. Executing Dynamic …

    Comment

    Working...