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

Variable column name

P: 2
I have a database(PostgreSQL) 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(column_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
Apr 24 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 534
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.
Apr 25 '07 #2

Post your reply

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