Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 014682E0158 for ; Mon, 26 Nov 2007 04:13:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 43853-07 for ; Mon, 26 Nov 2007 04:13:29 -0400 (AST) Received: from interscan.indicator.com (mail.indicator.be [193.121.199.3]) by postgresql.org (Postfix) with ESMTP id F2B7B2E0162 for ; Mon, 26 Nov 2007 04:13:36 -0400 (AST) Received: from webaccess.indicator.be ([10.100.1.7]) by interscan.indicator.com with InterScan Message Security Suite; Mon, 26 Nov 2007 09:11:05 +0100 Received: from DOMEXT-MTA by webaccess.indicator.bewith Novell_GroupWise; Mon, 26 Nov 2007 09:13:34 +0100 Message-Id: <474A8E32.A3DD.0030.0@indicator.be> X-Mailer: Novell GroupWise Internet Agent 7.0.1 Date: Mon, 26 Nov 2007 09:13:22 +0100 From: "Bart Degryse" To: Subject: Re: dynmic column names inside trigger? References: <20071120161258.GA27106@apartia.fr><4743F6E5.A3DD.0030.0@indicator.be> <20071123170611.GA31463@apartia.fr> In-Reply-To: <20071123170611.GA31463@apartia.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=__PartD7F1D732.0__=" X-imss-version: 2.049 X-imss-result: Passed X-imss-approveListMatch: *@indicator.be X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/129 X-Sequence-Number: 29657 --=__PartD7F1D732.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Functionally it's the same. The difference is that you don't have to = DECLARE a variable for assembling your return value. It's either func(intext IN text, outtext OUT text .... returns NULL AS ( BEGIN ... return; END; ); or=20 func(intext IN text) returns text AS ( DECLARE outtext text; BEGIN ... return outtext; END; ); =20 I find it especially handy when I want the function to return multiple = values (thus a record) which are not of a table type. The second way you would have to define a type for your return values = first and than use it in your function "My" way you would just write func(intext IN text, outfield1 OUT text, outfield2 OUT date, outfield3 = OUT integer) returns NULL AS (...); A third way is to define the return value(s) inside the function as type = record but than you have to name the output when you call the function func(intext IN text) returns record AS ( DECLARE rec record; BEGIN ... return rec; END; ); SELECT * FROM func('my input text') AS (field1 text, field2 date, = field3 integer); I find this less intuitive. =20 Buth in the end you just choose the technique you like best. I'm not aware = of any performance penalties for either technique. Anyone? =20 >>> Louis-David Mitterrand 2007-11-23 = 18:06 >>> On Wed, Nov 21, 2007 at 09:14:14AM +0100, Bart Degryse wrote: > I would do something like this (not tested, but conceptually working): > =20 > CREATE or replace FUNCTION sanitize_text(webtext IN text, cleantext OUT = text) AS > $body$ > BEGIN > cleantext =3D translate(webtext, E'\x92\x96', '''-'); > cleantext =3D regexp_replace(cleantext, E'\x9c', 'oe', 'g'); > cleantext =3D regexp_replace(cleantext, E'\x85', '...', 'g'); > END; > $body$ > LANGUAGE plpgsql VOLATILE RETURNS NULL ON NULL INPUT; Hi,=20 I was curious as to why you created this function with a prototype of=20 func(intext IN text, outtext OUT text) ... returns NULL instead of the usual func(intext text) ... returns TEXT=20 Is that a more efficient way? ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster --=__PartD7F1D732.0__= Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Description: HTML
Functionally it's the same. The difference is that you don't have to = DECLARE a variable for assembling your return value.
It's either
   func(intext IN text, outtext OUT text .... returns NULL = AS (
   BEGIN
      ...
      return;
   END;
   );
or
   func(intext IN text) returns text AS (
   DECLARE
      outtext text;
   BEGIN
      ...
      return outtext;
   END;
   );
 
I find it especially handy when I want the function to return = multiple values (thus a record) which are not of a table type.
The second way you would have to define a type for your return values = first and than use it in your function
"My" way you would just write
   func(intext IN text, outfield1 OUT text, outfield2 OUT = date, outfield3 OUT integer) returns NULL AS (...);
A third way is to define the return value(s) inside the function as = type record but than you have to name the output when you call the = function
   func(intext IN text) returns record AS (
   DECLARE
      rec record;
   BEGIN
      ...
      return rec;
   END;
   );
   SELECT * FROM func('my input text') AS (field1 text, = field2 date, field3 integer);
I find this less intuitive.
 
Buth in the end you just choose the technique you like best. I'm not = aware of any performance penalties for either technique. Anyone?
 

>>> Louis-David Mitterrand <vindex+lists-pgsql-sql@apa= rtia.org> 2007-11-23 18:06 >>>
On Wed, Nov 21, 2007 at = 09:14:14AM +0100, Bart Degryse wrote:
> I would do something like = this (not tested, but conceptually working):
> 
> CREATE = or replace FUNCTION sanitize_text(webtext IN text, cleantext OUT text) = AS
> $body$
> BEGIN
> cleantext =3D translate(webtext, = E'\x92\x96', '''-');
> cleantext =3D regexp_replace(cleantext, = E'\x9c', 'oe', 'g');
> cleantext =3D regexp_replace(cleantext, = E'\x85', '...', 'g');
> END;
> $body$
> LANGUAGE plpgsql = VOLATILE RETURNS NULL ON NULL INPUT;

Hi,

I was curious as = to why you created this function with a prototype of

func(intext = IN text, outtext OUT text) ... returns NULL

instead of the = usual

func(intext text) ... returns TEXT

Is that a more = efficient way?

---------------------------(end of broadcast)--------= -------------------
TIP 2: Don't 'kill -9' the postmaster
--=__PartD7F1D732.0__=--