Re: row numbering - Mailing list pgsql-general

From josue
Subject Re: row numbering
Date
Msg-id 422081EF.7080105@lamundial.hn
Whole thread Raw
In response to Re: row numbering  (Jeff Davis <jdavis-pgsql@empires.org>)
List pgsql-general
Jeff Davis wrote:
> Here's an example using plperl and global variables. The variables are
> local to a session so you don't have to worry about the counters
> interfering. If you need two counters in a session, just execute
> reset_counter().
>
> CREATE OR REPLACE FUNCTION reset_counter() RETURNS INT AS $$
> $_SHARED{counter} = 0;
> return 0;
> $$ LANGAUGE plperl;
>
> CREATE OR REPLACE FUNCTION counter() RETURNS INT AS $$
> return $_SHARED{counter}++;
> $$ LANGUAGE plperl;
>
> Now, you can execute the queries just like you want:
> select counter(),a,b from foo;
>
> There are a couple trivial issues, like you can start from 1 instead of
> 0 if you want.

Thanks, all the ideas you and the other members gave me have been very
helpfully


--
Sinceramente,
Josué Maldonado.

... "Ser fiel supone engañar a tu pareja en el momento justo"

pgsql-general by date:

Previous
From: Ragnar Hafstað
Date:
Subject: Re: basic trigger using OLD not working?
Next
From: Bruno Wolff III
Date:
Subject: Re: postgresql 8.0 on windows 2003 server