Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 9AB089FBF81 for ; Wed, 30 May 2007 14:29:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 18392-05-2 for ; Wed, 30 May 2007 14:28:58 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by postgresql.org (Postfix) with ESMTP id 7B5F19FB6DD for ; Wed, 30 May 2007 14:28:58 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c36so710501ana for ; Wed, 30 May 2007 10:28:47 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=m3oPRfXi0RrUjIJgYDbigY5N8oh4nH5LMVeM60AUq+u4TY9E4JkRI10Ah3f/ad7VTrj1iJ2dKpKBhzvU9PrcFfkJ/WcGNtqrFHmUeNENH12/Cpr0ACQx6K/trEMw5nc/E3JS9v+oJWJrXOCIlmfaQ/xXCEjiajZJFCGs666XeEg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ZiU9dHjHNd/5ErzawTlH3RH+Pn4BiFiAAR5XjCkC0/HrZxYtH3N+3BJwRTavTtTwRiei4obUn0r6328h52vE4vPWWz4YOD4INzqtE5Vud0KSBk17pwXav9DKMh0SUiAOwyQCOcAtv4zH1sfEAnney73r5GdsiPkOWrYqbr5E3hY= Received: by 10.100.128.8 with SMTP id a8mr6200692and.1180546127183; Wed, 30 May 2007 10:28:47 -0700 (PDT) Received: by 10.100.154.9 with HTTP; Wed, 30 May 2007 10:28:47 -0700 (PDT) Message-ID: Date: Wed, 30 May 2007 12:28:47 -0500 From: "=?UTF-8?Q?Rodrigo_De_Le=C3=B3n?=" To: pgsql-sql@postgresql.org, "Trigve Siver" Subject: Re: slow query execution In-Reply-To: <710412.41081.qm@web52709.mail.re2.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <710412.41081.qm@web52709.mail.re2.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/195 X-Sequence-Number: 28475 On 5/30/07, Trigve Siver wrote: > Can you point me to some sources > or give me some examples, please? CREATE OR REPLACE FUNCTION ROWNUM() RETURNS BIGINT AS $$ BEGIN RETURN NEXTVAL('ROWNUM_SEQ'); EXCEPTION WHEN OTHERS THEN CREATE TEMP SEQUENCE ROWNUM_SEQ; RETURN NEXTVAL('ROWNUM_SEQ'); END; $$ LANGUAGE 'PLPGSQL'; SELECT ROWNUM(), S.X FROM GENERATE_SERIES(5,1,-1) S(X); Remember to reset the sequence value if you use this more than once in the same session.