Re: 7.4 Wishlist

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: "Magnus Naeslund(f)" <mag(at)fbab(dot)net>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 7.4 Wishlist
Date: 2002-12-02 22:51:20
Message-ID: 20021202144827.I58766-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-advocacy pgsql-general pgsql-hackers

On Mon, 2 Dec 2002, Magnus Naeslund(f) wrote:

> Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> wrote:
> >
> > If you use a scalar subquery, yes, but I think a subselect in from
> > would help, maybe something like (if you want the total count)
> >
> > select table_name.id, sum(sum_col)||'/'||t2.count from table_name,
> > (select count(*) as count from table_name) as t2 group by
> > table_name.id,t2.count;
> >
> > or (if you want each count the counter per group) either
> >
> > select id, sum(sum_col)||'/'||count(*) from table_name
> > group by id;
> >
> > or
> >
> > select table_name.id, sum(sum_col)||'/'||t2.count from table_name,
> > (select id, count(*) as count from table_name group by id) as t2 where
> > table_name.id=t2.id group by table_name.id,t2.count;
> >
>
> Give it up already, i was MAKING A POINT, not trying to make an
> optimized count(*) thing :)
> There are other examples that you cannot get around, that will be
> evaluated more than once when a local "user variable" would make it not
> need to.

For most cases sticking an expression in a subselect in from works to not
re-evaluate it (unless it's correlated in which case I don't think local
variables help). It might not be as optimal in all cases, but probably is
sufficient in most cases.

In response to

Browse pgsql-advocacy by date

  From Date Subject
Next Message Hannu Krosing 2002-12-02 23:29:24 Re: 7.4 Wishlist
Previous Message Robert Treat 2002-12-02 22:37:44 Re: "Business of Open Source Software" conference

Browse pgsql-general by date

  From Date Subject
Next Message Hannu Krosing 2002-12-02 23:29:24 Re: 7.4 Wishlist
Previous Message Magnus Naeslund(f) 2002-12-02 22:51:02 Re: postmaster process

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthew T. O'Connor 2002-12-02 22:54:11 Re: Auto Vacuum Daemon (again...)
Previous Message Rod Taylor 2002-12-02 22:32:38 Re: PG 7.3: Query Meta Data with the JDBC-driver