I'm sorry for not being precise. The table is simple enough: it has only
those two integer fields (f1, f2) and a third text field f3 that has the
value I'm looking for. Fields f1 and f2 together are the primary key. An
example:
f1 f2 f3
1 1 'a'
1 2 'b'
2 1 'c'
2 4 'd'
.. .. ...
8 5 'z'
etc. Now I have a list of integer pairs to match f1 and f2 from that table;
let's say I have those values in a vector. For example:
{ (1, 2), (2, 1), (8, 5) }
I want the corresponding return values for f3:
{ b, c, z }
The problem is that I have to match the pair, so my SQL again would be
SELECT f3 FROM t
WHERE (f1 = 1 AND f2 = 2) OR (f1 = 2 AND f2 = 1) OR (f1 = 8 OR f2 = 5);
for the former example. I can guarantee that all the values I put in the OR
list exist in the table, and I want to know the f3 of each one, exactly. The
values from the list are arbitrary or random, and are not coming from a
SELECTion. I want to avoid the AND/OR list, because the vector could be very
long.
Thank you again for your help.
Leandro Fanzone.
Josh Berkus wrote:
> Leandro,
>
> > Maybe this is a silly question. I have a table t with two fields f1
> > and
> > f2. Those fields together form the primary key. I want to select a
> > list
> > of pairs from that table. The simplest SQL clause would be
> >
> > SELECT * FROM t WHERE (f1 = v1 AND f2 = v2) OR (f1 = v3 AND f2 = v4)
> > ...;
>
> We'll need database schema (table designs) if you want us to help you.
> The above isn't enough information to go on. For example, where did
> "v1" come from? Is this a field? An interface language variable?
>
> Please be explicit! Also, consider picking up Joe Celko's SQL for
> Smarties, reviewed at http://techdocs.postgresql.org/bookreviews.php
>
> -Josh
>
> ______AGLIO DATABASE SOLUTIONS___________________________
> Josh Berkus
> Complete information technology josh@agliodbs.com
> and data management solutions (415) 565-7293
> for law firms, small businesses fax 621-2533
> and non-profit organizations. San Francisco
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)