Re: example of Create Function

From: "Roberto (SmartBit)" <roberto(at)smartbit(dot)inf(dot)br>
To: "Joe Conway" <mail(at)joeconway(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: example of Create Function
Date: 2002-10-22 17:54:44
Message-ID: 001901c279f4$1cba2ea0$1501a8c0@NoteBook
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ned Lilly 2002-10-22 18:28:12 OpenMFG: PostgreSQL-backed ERP for small manufacturers
Previous Message Roberto (SmartBit) 2002-10-22 17:41:53 Re: PostgreSQL for Windows 2000