Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id DD53B9F9B05 for ; Mon, 18 Dec 2006 13:36:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 65626-01 for ; Mon, 18 Dec 2006 13:36:09 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by postgresql.org (Postfix) with ESMTP id B61769F9357 for ; Mon, 18 Dec 2006 13:36:09 -0400 (AST) Received: by an-out-0708.google.com with SMTP id c24so418982ana for ; Mon, 18 Dec 2006 09:36:09 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=NUjVAM9rvra8Bli34FVFyBEIdylOjbfUQZmImFufh+PhS4WOvU61Zhragr7siV5aeoRiIKzo+YMWIGN5NBKsYj+LPD5BzRzKTKeS7+EM30Gapdipq5PHa4MYL1tjLZVndqmJZTY+ba2KzQgBvE4GqMKyx/uDWHafzspMj14p+ws= Received: by 10.78.193.19 with SMTP id q19mr3223985huf.1166463367579; Mon, 18 Dec 2006 09:36:07 -0800 (PST) Received: by 10.78.131.9 with HTTP; Mon, 18 Dec 2006 09:36:07 -0800 (PST) Message-ID: Date: Mon, 18 Dec 2006 11:36:07 -0600 From: "Aaron Bono" To: "Carlos Santos" Subject: Re: SELECT with WHERE clause by column number Cc: "Lista PostgreSQL SQL" In-Reply-To: <20061218171739.98671.qmail@web57105.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_17579_54901.1166463367458" References: <20061218171739.98671.qmail@web57105.mail.re3.yahoo.com> X-Google-Sender-Auth: b7dac305771fefc5 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/130 X-Sequence-Number: 27086 ------=_Part_17579_54901.1166463367458 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 12/18/06, Carlos Santos wrote: > > Hi! > > I need to make a query like this: > > 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... > > Can I do this with a single query or in a faster way through SQL, an > internal function or through a Procedural Language? > Can you provide the 2 queries you used to successfully do this in two database calls? I am not sure that select makes sense. Where clauses work on rows, not columns. Having your two working queries will help us see what you are really trying to do. -- ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com http://codeelixir.com ================================================================== ------=_Part_17579_54901.1166463367458 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 12/18/06, Carlos Santos <carloscompels@yahoo.com.br> wrote:
Hi!

I need to make a query like this:

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...

Can I do this with a single query or in a faster way through SQL, an internal function or through a Procedural Language?

Can you provide the 2 queries you used to successfully do this in two database calls?

I am not sure that select makes sense.  Where clauses work on rows, not columns.  Having your two working queries will help us see what you are really trying to do.

--
==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
================================================================== ------=_Part_17579_54901.1166463367458--