Re: Out parameters handling - Mailing list pgsql-hackers

From Dimitri Fontaine
Subject Re: Out parameters handling
Date
Msg-id 04CCAC7D-AE82-4FD0-BDD0-6CBC07CA1C31@hi-media.com
Whole thread Raw
In response to Re: Out parameters handling  (Josh Berkus <josh@agliodbs.com>)
Responses Re: Out parameters handling  (Dimitri Fontaine <dfontaine@hi-media.com>)
Re: Out parameters handling  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

Le 7 mars 09 à 02:44, Josh Berkus a écrit :
> Thing is, anybody can institute their own naming convention.  I've
> long used v_ as a prefix.  Allowing : would save me some keystrokes,
> but that's about it.

What I usually do in those cases is abusing the ALIAS option of
DECLARE (because as mentioned somewhere else in this thread, you
generally don't want to have that ugly OUT parameters, you want a nice
API) :

CREATE OR REPLACE FUNCTION test_out (  IN  a integer,  IN  b integer,  OUT s integer ) RETURNS setof integer LANGUAGE
PLPGSQL
AS $f$
DECLARE  v_s ALIAS FOR $3;
BEGIN  FOR v_s IN SELECT generate_series(a, b)  LOOP    v_s := v_s * v_s;    RETURN NEXT;  END LOOP;  RETURN;
END;
$f$;

CREATE FUNCTION
dim=# SELECT * FROM test_out(2, 4); s
----  4  9 16
(3 rows)

I'd sure be happy not having to do it explicitly, but schema-style
prefixing has the drawback of needing to avoid any user defined
schema. Maybe pg_plout would do?

Regards,
--
dim





pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_hba.conf - patch to report all parsing errors, and then bail
Next
From: Dimitri Fontaine
Date:
Subject: Re: Out parameters handling