Re: Using arguments with functions - Mailing list pgsql-general

From Oliver Elphick
Subject Re: Using arguments with functions
Date
Msg-id 1089490126.3503.60.camel@linda
Whole thread Raw
In response to Using arguments with functions  ("Robert Fitzpatrick" <robert@webtent.com>)
List pgsql-general
On Sat, 2004-07-10 at 20:50, Robert Fitzpatrick wrote:
> While this function works when hard coded, the following will not when
> trying the same thing with a argument. Can someone point to me what I'm
> doing wrong?
...

> This does not work:
>
> CREATE OR REPLACE FUNCTION "public"."get_next" (varchar) RETURNS varchar AS'
> DECLARE
>   var1 alias for $1;
>
> BEGIN
>   var1 = chr( (ascii(var1) + 1) );
...
> ERROR:  "$1" is declared CONSTANT

You are trying to change the passed parameter.

Instead do

        DECLARE
           var1   varchar;
        BEGIN
           var1 = chr( (ascii($1) + 1) );

which I think should work.

--
Oliver Elphick                                          olly@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
                 ========================================
     "Delight thyself also in the LORD; and he shall give
      thee the desires of thine heart."
                                  Psalms 37:4


pgsql-general by date:

Previous
From: "Robert Fitzpatrick"
Date:
Subject: Using arguments with functions
Next
From: Tom Lane
Date:
Subject: Re: Using arguments with functions