Re: IN vs EXIIST - Mailing list pgsql-general

From Jochem van Dieten
Subject Re: IN vs EXIIST
Date
Msg-id 1032433195.3d89ae2b96ff5@webmail.oli.tudelft.nl
Whole thread Raw
In response to IN vs EXIIST  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
List pgsql-general
Quoting Jean-Christian Imbeault <jc@mega-bucks.co.jp>:
>
> The reason being that key1 is not a primary key (key1, key2 is the
> primary key). i.e. I have a table like this
>
> key1    key2    x
> ------------------
> a    1    t
> a    2    t
> a    3    f
> b    1    t
> b    2    t
> b    3    t
> c    3    t
> c    4    f
>
> So basically I want key1 values for which all the X's are true.

SELECT     key1, Min(CASE WHEN x THEN 1 ELSE 0 END) AS isTrue
FROM       table
GROUP BY   key1
HAVING     isTrue = 1


> Or is my table schema wrong?

I generally don't design tables with composite keys. I find it to
complicated in many operations. But on occasion I have seen them being
used by others very efficiently.

Jochem

pgsql-general by date:

Previous
From: Jean-Christian Imbeault
Date:
Subject: Re: IN vs EXIIST
Next
From: "Ben-Nes Michael"
Date:
Subject: pg_dump in 7.1.3 and migration to 7.2.2