Re: Filter tables

From: Reg Me Please <regmeplease(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Dimitri Fontaine <dfontaine(at)hi-media(dot)com>, Erik Jones <erik(at)myemma(dot)com>
Subject: Re: Filter tables
Date: 2007-11-12 16:25:59
Message-ID: 200711121725.59492.regmeplease@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Il Monday 12 November 2007 17:05:18 Dimitri Fontaine ha scritto:
> Hi,
>
> Le lundi 12 novembre 2007, Reg Me Please a écrit :
> > What I'd need to do is to "filter" t1 against f1 to get only the rows
> > ( 'field1',1 ) and ( 'field2',1 ).
>
> select * from t1 natural join f1 where t1.id = 1;
> t | id
> --------+----
> field1 | 1
> field2 | 1
> (2 lignes)
>
>
> I'm not sure about how you wanted to filter out the ('field1', 2) row of
> table t1, so used the where t1.id = 1 restriction.
>
> Hope this helps,

I think surely I've not been clean enough.

The rows in t1 should be seen as grouped by the field id. A group of such
rouws matches the filter f1 (made by two rows in my example) if I can find
all the values of f1 in the field t of that group.

So, in my example, in t1 the group of rows with id=2 (actually made by only
one row in my example) doesn't match the filter because it's lacking a row
with t='field2'.
In the same way the group of rows with id=3 won't match as they lack both
values that are in f1.

What I'd like to see as an output of the query/function is

id
----
1

as only the group with id=1 has both the values.
Of course, f1 could have any number of different values.

--
Reg me Please

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-11-12 16:26:09 Re: Regression in 8.3?
Previous Message Erik Jones 2007-11-12 16:25:13 Re: Regression in 8.3?