X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 70C44D1B508 for ; Sun, 28 Sep 2003 05:25:01 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 86876-01 for ; Sun, 28 Sep 2003 02:24:31 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id CAFE1D1B4E8 for ; Sun, 28 Sep 2003 02:24:29 -0300 (ADT) Received: from [192.168.5.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.3) with ESMTP-TLS id 390154; Sat, 27 Sep 2003 22:24:01 -0700 Message-ID: <3F766FD5.3080001@joeconway.com> Date: Sat, 27 Sep 2003 22:21:25 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Richard Sydney-Smith Cc: pgsql-sql@postgresql.org Subject: Re: Mystery function error References: <000c01c38572$73c03c50$251a32d2@athlon2000> In-Reply-To: <000c01c38572$73c03c50$251a32d2@athlon2000> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/356 X-Sequence-Number: 15334 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