From: | Dimitri Fontaine <dfontaine(at)hi-media(dot)com> |
---|---|
To: | Josh Berkus <josh(at)agliodbs(dot)com> |
Cc: | Robert Haas <robertmhaas(at)gmail(dot)com>, Asko Oja <ascoja(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Out parameters handling |
Date: | 2009-03-07 18:56:12 |
Message-ID: | 04CCAC7D-AE82-4FD0-BDD0-6CBC07CA1C31@hi-media.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Dimitri Fontaine | 2009-03-07 19:29:08 | Re: Out parameters handling |
Previous Message | Tom Lane | 2009-03-07 18:51:49 | Re: pg_hba.conf - patch to report all parsing errors, and then bail |