Variable column name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imauser
    New Member
    • Apr 2007
    • 2

    Variable column name

    I have a database(Postgr eSQL) table(about 70k rows).I am developing an ASP
    webpage and there is a list-box on it which contains the name of the
    columns of that table. User selects the column name from that box and a
    query is sent to the database. The data from that column should be
    returned to the user.

    Now the problem is that, I have seen the 'SELECT' statements with the
    exact column name written in it.But in my case the column name is
    variable.So, I am not able to understand how should I write such
    query,where column name is like a parameter passed by the user.I am
    working in .net for developing the webpage.

    I tried to use a prepare statement....

    PREPARE statement(text) AS SELECT $1 FROM table_name;
    EXECUTE statement(colum n_name);

    this returns....

    ?column?
    ---------------
    column_name
    column_name
    column_name
    column_name
    column_name
    ..........
    ..........
    column_name


    I can't figure out the problem in this .........if there is another solution to this plz suggest.......

    thanx
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    Although this manual does not say it explicitely, I don't think you can pass a table name, or a column name as an argument to prepared statement.

    Try to run the plain SQL query instead.
    Last edited by michaelb; Apr 25 '07, 04:38 PM. Reason: Corrected my answer

    Comment

    Working...