Connecting Tech Pros Worldwide Forums | Help | Site Map

queries in postgresql

Newbie
 
Join Date: Apr 2007
Posts: 2
#1: Apr 24 '07
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.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: Apr 26 '07

re: queries in postgresql


Quote:

Originally Posted by imauser

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 have done the following, something similar may work for you:
Expand|Select|Wrap|Line Numbers
  1. query= "SELECT * FROM myTable WHERE idnum=" & request("id")
  2. '...
  3. 'open the db and recordset
  4.  
  5. for each x in rs.fields
  6.    if request(x) <> "" then
  7.       rs(x) = request(x)
  8.    end if
  9. next
  10.  
  11. rs.update
  12.  
In the SELECT statement I just opened all of the columns. Then I went through each field and if a request(that field name) exists and has data, the data was set to that request variable.

Would something like that work for you?

Jared
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Apr 26 '07

re: queries in postgresql


or were you just looking for
Expand|Select|Wrap|Line Numbers
  1. query = "SELECT " & request.form("column") & " WHERE ...
?

Jared
Reply


Similar ASP / Active Server Pages bytes