From: | josue <josue(at)lamundial(dot)hn> |
---|---|
To: | Jeff Davis <jdavis-pgsql(at)empires(dot)org> |
Cc: | PgSQL General List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: row numbering |
Date: | 2005-02-26 14:04:31 |
Message-ID: | 422081EF.7080105@lamundial.hn |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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"
From | Date | Subject | |
---|---|---|---|
Next Message | Ragnar Hafstað | 2005-02-26 14:09:14 | Re: basic trigger using OLD not working? |
Previous Message | Benjamin | 2005-02-26 13:43:08 | Re: db replication and errors |