pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: elein <elein@varlena.com>
To: Greg Stark <gsstark@mit.edu>
Cc: elein <elein@varlena.com>
Cc: Josh Berkus <josh@agliodbs.com>
Cc: Rod Taylor <pg@rbt.ca>
Cc: Jeff Boes <jboes@nexcerpt.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL challenge--top 10 for each key value?
Date: Sun, 11 Apr 2004 11:20:42 -0700
Message-ID: <20040411112042.B9217@cookie.varlena.com> (raw)
In-Reply-To: <871xmvf7sz.fsf@stark.xeocode.com>
References: <33af4fa4e4ec230574cefcff737ea40a@news.teranews.com>
	<87r7uyf3ki.fsf@stark.xeocode.com>
	<1081481466.56361.808.camel@jester>
	<200404090906.39541.josh@agliodbs.com>
	<20040410164651.K409@cookie.varlena.com>
	<871xmvf7sz.fsf@stark.xeocode.com>

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



view thread (16+ messages)  latest in thread

Message-ID: <20040411112042.B9217@cookie.varlena.com>
Permalink:  ../20040411112042.B9217@cookie.varlena.com/
Also on:    postgresql.org/message-id/20040411112042.B9217@cookie.varlena.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: elein@varlena.com, gsstark@mit.edu, josh@agliodbs.com, pg@rbt.ca, jboes@nexcerpt.com
  Subject: Re: SQL challenge--top 10 for each key value?
  In-Reply-To: <20040411112042.B9217@cookie.varlena.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox