pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ragnar <gnari@hive.is>
To: Carlos Santos <carlos@compels.net>
Cc: Lista PostgreSQL SQL <pgsql-sql@postgresql.org>
Subject: Re: SELECT with WHERE clause by column number
Date: Mon, 18 Dec 2006 21:56:28 +0000
Message-ID: <1166478988.6369.238.camel@localhost.localdomain> (raw)
In-Reply-To: <20061218171739.98671.qmail@web57105.mail.re3.yahoo.com>
References: <20061218171739.98671.qmail@web57105.mail.re3.yahoo.com>

On mán, 2006-12-18 at 09:17 -0800, 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...
> 
> Can I do this with a single query or in a faster way through SQL, an
> internal function or through a Procedural Language?

this can be done with the more dynamic prodedural languages.

this should be possible too with pl/pgsql using your first query
+ EXECUTE
this is still 2 queries, but only one client round-trip.

this can also be done in one SQL query with some creative
misuse of an UNION ALL within a subquery, if you know the 
number of columns in your table.

gnari







view thread (4+ messages)

Message-ID: <1166478988.6369.238.camel@localhost.localdomain>
Permalink:  ../1166478988.6369.238.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1166478988.6369.238.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gnari@hive.is, carlos@compels.net
  Subject: Re: SELECT with WHERE clause by column number
  In-Reply-To: <1166478988.6369.238.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox