Re: trivial sql help

From: Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: trivial sql help
Date: 2002-10-10 17:52:56
Message-ID: 20021010185256.T6842@quartz.newn.cam.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 10, 2002 at 09:14:41AM -0700, Stephan Szabo wrote:
>
> 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?

pers_comp relates person to computer. 99% of students have 1 computer =>
only one pers_comp(p,c) entry. I just wanted to fill in the computer's id
into the request of a given person for the simple case.

Anyway, I was just having brain failure.. as you have all happily explained
away the error message, I'll try again..

Cheers,

Patrick

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hector Galicia 2002-10-10 17:58:03 cursors
Previous Message Patrick Welche 2002-10-10 17:48:39 Re: trivial sql help