Re: SQL challenge--top 10 for each key value?

Поиск
Список
Период
Сортировка
От elein
Тема Re: SQL challenge--top 10 for each key value?
Дата
Msg-id 20040411112042.B9217@cookie.varlena.com
обсуждение исходный текст
Ответ на Re: SQL challenge--top 10 for each key value?  (Greg Stark <gsstark@mit.edu>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: cursors and for loops?
Следующее
От: Bret Hughes
Дата:
Сообщение: Re: trigger/for key help