Re: SQL challenge--top 10 for each key value? - Mailing list pgsql-sql

From elein
Subject Re: SQL challenge--top 10 for each key value?
Date
Msg-id 20040411112042.B9217@cookie.varlena.com
Whole thread Raw
In response to Re: SQL challenge--top 10 for each key value?  (Greg Stark <gsstark@mit.edu>)
List pgsql-sql
No, it will not work twice in the same query as is.

If you want to code two counter buckets and pass in
some way to distinguish between the two yada yada yada
it is possible.  It is also possible to code this to
do multi-level counting/breaks/calculations, etc.

But the SD dictionary is by connection. So any values
stored in it need to be initialized at the appropriate
time *outside* of the first use.

elein

On Sun, Apr 11, 2004 at 12:38:20AM -0400, Greg Stark wrote:
> 
> elein <elein@varlena.com> writes:
> 
> > create or replace function pycounter(integer)
> > returns integer as
> > '
> >    if args[0] == 0:
> >       SD["nextno"] = 1
> >       return SD["nextno"]
> >    try:
> >       SD["nextno"] += 1
> >    except:
> >       SD["nextno"] = 1
> >    return SD["nextno"]
> > ' language 'plpythonu';
> > 
> > And clearly it can be done faster as a little
> > C function.
> 
> Does this approach have a hope of working if it's used twice in the same
> query?
> 
> 
> -- 
> greg
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: cursors and for loops?
Next
From: Bret Hughes
Date:
Subject: Re: trigger/for key help