Re: Mystery function error - Mailing list pgsql-sql

From Joe Conway
Subject Re: Mystery function error
Date
Msg-id 3F766FD5.3080001@joeconway.com
Whole thread Raw
In response to Mystery function error  ("Richard Sydney-Smith" <richard@ibisaustralia.com>)
List 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




pgsql-sql by date:

Previous
From: "Richard Sydney-Smith"
Date:
Subject: Mystery function error
Next
From: Josh Berkus
Date:
Subject: Re: Mystery function error