Re: 7.4 Wishlist

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: "Magnus Naeslund(f)" <mag(at)fbab(dot)net>
Cc: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 7.4 Wishlist
Date: 2002-12-02 21:40:49
Message-ID: 20021202133242.A57292-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:

> Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> wrote:
> >> Mysql is planning on making this work:
> >>
> >> SELECT id, @a:=COUNT(*), SUM(sum_col)/@a FROM table_name GROUP BY
> >> id.
> >>
> >> Do we have anything like it (After a discussion with Tom i figure
> >> no). User variables is nice, especially in these kind of queries.
> >
> > Well of course they have to make that work - they don't have
> > subselects :P
> >
> > Chris
>
> Yeah, but there is a point about running count(*) one time too many.
> Say if i would like to get a prettyprinting query like this:
>
> SELECT id, @a:=COUNT(*), sum_col::text||'/'@a::text FROM table_name;
>
> That would be DAMN expensive doing with a subselect:
>
> SELECT id, sum_col||'/'||(select COUNT(*) from tabe_name) FROM
> table_name;
>
> I know this example suck eggs, but you get the point where it hurts,
> right?

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;

In response to

Responses

Browse pgsql-advocacy by date

  From Date Subject
Next Message Magnus Naeslund(f) 2002-12-02 22:18:13 Re: 7.4 Wishlist
Previous Message Medi Montaseri 2002-12-02 21:02:30 Re: Segmentation fault while COPY in 7.3

Browse pgsql-general by date

  From Date Subject
Next Message Hunter Hillegas 2002-12-02 21:45:16 Re: 7.3 on OS X HOWTO
Previous Message Eric B.Ridge 2002-12-02 21:39:04 Re: 7.3 on OS X HOWTO

Browse pgsql-hackers by date

  From Date Subject
Next Message snpe 2002-12-02 22:08:56 Re: PG 7.3: Query Meta Data with the JDBC-driver
Previous Message Joe Conway 2002-12-02 21:30:13 Re: protecting prosrc (was Re: [GENERAL] USAGE on schema