Re: Using arguments with functions

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Robert Fitzpatrick <robert(at)webtent(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using arguments with functions
Date: 2004-07-10 20:08:46
Message-ID: 1089490126.3503.60.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)lfix(dot)co(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-07-10 20:33:26 Re: Using arguments with functions
Previous Message Robert Fitzpatrick 2004-07-10 19:50:30 Using arguments with functions