pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Richard Sydney-Smith <richard@ibisaustralia.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Mystery function error
Date: Sat, 27 Sep 2003 22:21:25 -0700
Message-ID: <3F766FD5.3080001@joeconway.com> (raw)
In-Reply-To: <000c01c38572$73c03c50$251a32d2@athlon2000>
References: <000c01c38572$73c03c50$251a32d2@athlon2000>

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





view thread (10+ messages)  latest in thread

Message-ID: <3F766FD5.3080001@joeconway.com>
Permalink:  ../3F766FD5.3080001@joeconway.com/
Also on:    postgresql.org/message-id/3F766FD5.3080001@joeconway.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mail@joeconway.com, richard@ibisaustralia.com
  Subject: Re: Mystery function error
  In-Reply-To: <3F766FD5.3080001@joeconway.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox