Re: example of Create Function - Mailing list pgsql-general

From Roberto (SmartBit)
Subject Re: example of Create Function
Date
Msg-id 001901c279f4$1cba2ea0$1501a8c0@NoteBook
Whole thread Raw
In response to example of Create Function  ("Roberto (SmartBit)" <roberto@smartbit.inf.br>)
List pgsql-general
>
> Your example is not possible with any PL in PostgreSQL versions prior to
7.3
> (currently in beta testing). However, in 7.3, using PL/pgSQL it looks like
this:

by the way, when does it will be done???


>
> CREATE OR REPLACE FUNCTION my_proc(TIMESTAMP)
> RETURNS SETOF payments
> AS '
> DECLARE
>     rec RECORD;
> BEGIN
>     FOR rec IN SELECT * FROM payments
>     WHERE r_date_payment BETWEEN $1 AND CURRENT_TIMESTAMP LOOP
>        /*here I can do any check for each row of SELECT above!! */


     would I be able to change the value of field? like:
          IF r_value < 0 THEN
             r_value = r_value*-1;


>        RETURN NEXT rec; /* Each RETURN NEXT command returns a row */
>     END LOOP;
>     RETURN;
> END;
> ' LANGUAGE 'plpgsql';
>
> See:
>
http://developer.postgresql.org/docs/postgres/plpgsql-control-structures.htm
l
> and
>   http://developer.postgresql.org/docs/postgres/xfunc-tablefunctions.html
>
> HTH,
>
> Joe
>
>


pgsql-general by date:

Previous
From: Tommi Maekitalo
Date:
Subject: Re: 7.1.3 : pg_dumpall does not work for me
Next
From: pilsl@goldfisch.at
Date:
Subject: Re: 7.1.3 : pg_dumpall does not work for me