Re: [GENERAL] Functions - Mailing list pgsql-general

From Aaron J. Seigo
Subject Re: [GENERAL] Functions
Date
Msg-id 99110316023708.00702@stilborne
Whole thread Raw
In response to Functions  (Simon Drabble <simon@eskimo.com>)
Responses Re: [GENERAL] Functions
List pgsql-general
hi...

>   CREATE FUNCTION fn_fubar(int4) AS
>   'UPDATE foo SET bar = tmp.numb FROM tmp WHERE tmp.numb = $$'
>   LANGUAGSE 'sql';

i hate $1, $2 personally.. they make my eyes cross eventually (esp. once you
have 3 or 4 params.. ick) and they are hard to maintain in larger functions
(what was that $2 param again???)

so i usually use pl/pgsql and do this:

   CREATE FUNCTION fn_fubar(int4) returns int4 AS '
     DECLARE
        myParam   alias for $1;
     BEGIN
       UPDATE foo SET bar = tmp.numb FROM tmp WHERE tmp.numb = myParam;
       return myParam;
     END; '
   LANGUAGSE 'pl/pgsql';

more typing, but easier to read and maintain later... but then, i'm picky.

--
Aaron J. Seigo
Sys Admin

pgsql-general by date:

Previous
From: Andrew Perrin - Demography
Date:
Subject: Re: [GENERAL] Functions
Next
From: Simon Drabble
Date:
Subject: Re: [GENERAL] Functions