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 BF696D1D097 for ; Sun, 11 Apr 2004 01:38:23 -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 22127-02 for ; Sun, 11 Apr 2004 01:38:22 -0300 (ADT) Received: from smtp.istop.com (dci.doncaster.on.ca [66.11.168.194]) by svr1.postgresql.org (Postfix) with ESMTP id 4DBECD1CACC for ; Sun, 11 Apr 2004 01:38:21 -0300 (ADT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by smtp.istop.com (Postfix) with ESMTP id E538717C425; Sun, 11 Apr 2004 00:38:20 -0400 (EDT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1BCWjc-0004yj-00; Sun, 11 Apr 2004 00:38:20 -0400 To: elein Cc: Josh Berkus , Rod Taylor , Greg Stark , Jeff Boes , pgsql-sql@postgresql.org Subject: Re: SQL challenge--top 10 for each key value? 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> In-Reply-To: <20040410164651.K409@cookie.varlena.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 11 Apr 2004 00:38:20 -0400 Message-ID: <871xmvf7sz.fsf@stark.xeocode.com> Lines: 25 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/102 X-Sequence-Number: 17477 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