Re: trivial sql help - Mailing list pgsql-general

From Stephan Szabo
Subject Re: trivial sql help
Date
Msg-id 20021010091100.C17293-100000@megazone23.bigpanda.com
Whole thread Raw
In response to trivial sql help  (Patrick Welche <prlw1@newn.cam.ac.uk>)
Responses Re: trivial sql help  (Patrick Welche <prlw1@newn.cam.ac.uk>)
List pgsql-general
On Thu, 10 Oct 2002, Patrick Welche wrote:

> update rawrequest
>    set cid=(select pc.c
>               from pers_comp as pc
>              where pc.p=pid
>              group by pc.c
>             having count(pc.c)=1
>            )
>  where pr
> ;
>
> ERROR:  More than one tuple returned by a subselect used as an expression.
>
> pid, pc.p, pc.c, cid are all integers. pc just has 2 columns p and c.
>
> I thought putting the count()=1 in there would force a single tuple..

No, that'll limit you only to groups having a count of 1.  It'll still
give multiple groups.  You could probably use limit to get 1 row, but
what's the actual behavior you want the update to have?



pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: trivial sql help
Next
From: Patrick Welche
Date:
Subject: Re: trivial sql help