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"
---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@xxxxxxxxxxxxxx