Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 100A89F9357 for ; Mon, 18 Dec 2006 13:25:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 39105-03 for ; Mon, 18 Dec 2006 13:25:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id EB6AC9F9B05 for ; Mon, 18 Dec 2006 13:25:38 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 347A874A89; Mon, 18 Dec 2006 17:25:28 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 10D58FF05; Mon, 18 Dec 2006 17:25:28 +0000 (GMT) Message-ID: <4586CF07.9000900@archonet.com> Date: Mon, 18 Dec 2006 17:25:27 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5.0.8 (X11/20061115) MIME-Version: 1.0 To: Carlos Santos Cc: Lista PostgreSQL SQL Subject: Re: SELECT with WHERE clause by column number References: <20061218171739.98671.qmail@web57105.mail.re3.yahoo.com> In-Reply-To: <20061218171739.98671.qmail@web57105.mail.re3.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/129 X-Sequence-Number: 27085 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