Re: Mystery function error

From: Joe Conway <mail(at)joeconway(dot)com>
To: Richard Sydney-Smith <richard(at)ibisaustralia(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Mystery function error
Date: 2003-09-28 05:21:25
Message-ID: 3F766FD5.3080001@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Richard Sydney-Smith wrote:
> CREATE OR REPLACE FUNCTION public.locate(bpchar, bpchar) RETURNS
> int4 AS ' -- search for the position of $2 in $1
>
> declare srcstr alias for $1; searchstr alias for $2;
>
> begin return position(searchstr in srcstr); ' LANGUAGE 'plpgsql'
> VOLATILE;

You are missing the "end" keyword in there. Also, I'd think this
function is IMMUTABLE not VOLATILE.

CREATE OR REPLACE FUNCTION public.locate(bpchar, bpchar)
RETURNS int4 AS '
-- search for the position of $2 in $1
declare
srcstr alias for $1;
searchstr alias for $2;
begin
return position(searchstr in srcstr);
end;
' LANGUAGE 'plpgsql' IMMUTABLE;

This could also be done as:

CREATE OR REPLACE FUNCTION public.locate(bpchar, bpchar)
RETURNS int4 AS '
select position($2 in $1)
' LANGUAGE 'sql';

HTH,

Joe

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-09-28 05:28:07 Re: Mystery function error
Previous Message Richard Sydney-Smith 2003-09-28 03:39:19 Mystery function error