Re: how to cache subtotals -- with subselect? - Mailing list pgsql-general

From Stephan Szabo
Subject Re: how to cache subtotals -- with subselect?
Date
Msg-id 20030302230634.F34246-100000@megazone23.bigpanda.com
Whole thread Raw
In response to how to cache subtotals -- with subselect?  (Will Trillich <will@serensoft.com>)
Responses Re: how to cache subtotals -- with subselect?  (Will Trillich <will@serensoft.com>)
List pgsql-general
On Mon, 3 Mar 2003, Will Trillich wrote:

> i'm having some trouble finding the error here -- we're trying
> to cache subtotals from subset tables:
>
> db=# select
> db-#    -- person last-name:
> db-#    p.lname,
> db-#    -- CACHED subtotals where team involvement == 'client':
> db-#    p.been_client,
> db-#    -- LIVE subtotals where team involvement == 'client':
> db-#    (
> db(#      select count(*)
> db(#      from team t join involv_v v on (t.involv_v=v.id)
> db(#      where t.person=p.id and v.name='Client'
> db(#    ) as ct
> db-# from _person p;
>
>   lname   | been_client | ct
> ----------+-------------+----
>  Trillich |           4 |  0 <== whoops
>  Tharp    |           0 |  0
>  Stiles   |           0 |  0
> (3 rows)
>
> here, 'trillich' has person.been_client = 4 which should instead
> be 0 (that is, of the projects he's involved with, none are
> as a 'client'). so...
>
> db=#  update _person set
> db-#  been_client = (
> db(#     select count(*) from team t join involv_v v on (v.id=t.involv_v)
> db(#     where v.name='Client' and t.person=person.id
> db(#  );
> NOTICE:  Adding missing FROM-clause entry in subquery for table "person"
> UPDATE 3
>
> three? that's not right. and what's up with adding a from
> clause? the outer query already has a reference to _person which
> the inner needs to use.

But the inner doesn't have a reference to _person, it has a reference to
person, was it intentional to use different tables in those two places?



pgsql-general by date:

Previous
From: Will Trillich
Date:
Subject: how to cache subtotals -- with subselect?
Next
From: Will Trillich
Date:
Subject: Re: how to cache subtotals -- with subselect?