Skip site navigation (1) Skip section navigation (2)

Re: SELECT with WHERE clause by column number

From: Richard Huxton <dev(at)archonet(dot)com>
To: Carlos Santos <carlos(at)compels(dot)net>
Cc: Lista PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: SELECT with WHERE clause by column number
Date: 2006-12-18 17:25:27
Message-ID: 4586CF07.9000900@archonet.com (view raw or flat)
Thread:
Lists: pgsql-sql
Carlos Santos wrote:
> SELECT id FROM myTable WHERE column-number = 'value';
> (PS: The id column is the primary key of myTable).
> 
> That is a select using column number in the WHERE clause what don't exists in SQL.
> 
> I need this because there's a situation in my program where I don't have the column name.
> I've solved that querying Postgresql the name of the column with that number, and then creating  the SELECT query.
> But this solution is slow... two database calls...

If you don't know what the column is, how do you know what you are 
testing against? Or what type it is, for that matter?

Anyway, just have build a list of column-name,column-type pairs for 
relevant tables at application start-up, or store it in a configuration 
file. Unless you're building/changing tables all the time, that should work.

I'm curious as to what type of application can usefuly query a database 
without knowing what structure it has.

-- 
   Richard Huxton
   Archonet Ltd

In response to

pgsql-sql by date

Next:From: Aaron BonoDate: 2006-12-18 17:36:07
Subject: Re: SELECT with WHERE clause by column number
Previous:From: Carlos SantosDate: 2006-12-18 17:17:39
Subject: SELECT with WHERE clause by column number

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group