X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DBDA9D1D4C3 for ; Sun, 11 Apr 2004 15:22:40 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 95472-05 for ; Sun, 11 Apr 2004 15:22:44 -0300 (ADT) Received: from cookie.varlena.com (adsl-64-142-36-103.sonic.net [64.142.36.103]) by svr1.postgresql.org (Postfix) with ESMTP id DFBD6D1D2C6 for ; Sun, 11 Apr 2004 15:22:38 -0300 (ADT) Received: by cookie.varlena.com (Postfix on SuSE Linux 7.3 (i386), from userid 500) id CD8F6394B8; Sun, 11 Apr 2004 11:20:42 -0700 (PDT) Date: Sun, 11 Apr 2004 11:20:42 -0700 From: elein To: Greg Stark Cc: elein , Josh Berkus , Rod Taylor , Jeff Boes , pgsql-sql@postgresql.org Subject: Re: SQL challenge--top 10 for each key value? Message-ID: <20040411112042.B9217@cookie.varlena.com> Mail-Followup-To: Greg Stark , Josh Berkus , Rod Taylor , Jeff Boes , pgsql-sql@postgresql.org 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <871xmvf7sz.fsf@stark.xeocode.com> User-Agent: Mutt/1.3.22.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/107 X-Sequence-Number: 17482 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 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