Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 175B32E005D for ; Wed, 14 May 2008 17:36:25 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 28637-09 for ; Wed, 14 May 2008 17:36:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ti-out-0910.google.com (ti-out-0910.google.com [209.85.142.191]) by developer.postgresql.org (Postfix) with ESMTP id A6FDE2E0047 for ; Wed, 14 May 2008 17:36:17 -0300 (ADT) Received: by ti-out-0910.google.com with SMTP id y8so49079tia.5 for ; Wed, 14 May 2008 13:36:15 -0700 (PDT) Received: by 10.150.50.3 with SMTP id x3mr1592947ybx.30.1210797373889; Wed, 14 May 2008 13:36:13 -0700 (PDT) Received: by 10.150.134.13 with HTTP; Wed, 14 May 2008 13:36:13 -0700 (PDT) Message-ID: <937d27e10805141336l601c4aa2x8972c2bd7fda07e6@mail.gmail.com> Date: Wed, 14 May 2008 21:36:13 +0100 From: "Dave Page" To: "Premil Agarwal" Subject: Re: [INTERFACES] Function's final statement must be a SELECT Cc: pgsql-interfaces@postgresql.org, pgsql-admin@postgresql.org In-Reply-To: <92aa956e0805141323y3c14fe2p4e10ba9c67637c49@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <92aa956e0805141323y3c14fe2p4e10ba9c67637c49@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/127 X-Sequence-Number: 29211 On Wed, May 14, 2008 at 9:23 PM, Premil Agarwal wrote: > I am trying to write a function in PgAdmin 1.8.2 for postgres 8.3. The > function should check the input parameter for NULL. If its NULL then > function should return 'Auto' otherwise return the input as such. > > CREATE FUNCTION check_for_null( inp character varying) RETURNS character > varying AS $$ > DECLARE > temp1 character varying := 'Auto'; > temp2 character varying := inp; > BEGIN > > IF temp2 IS NOT NULL THEN > temp1 := temp2; > END IF; > > RETURN temp1; > END; > $$ LANGUAGE SQL; > > When I hit 'OK' in create function window, I get following error :- > > ERROR: return type mismatch in function declared to return character varying > DETAIL: Function's final statement must be a SELECT. > CONTEXT: SQL function "check_for_null" > > Any suggestions why this happens ?? Choose pl/pgsql as the language, not SQL. -- Dave Page EnterpriseDB UK: http://www.enterprisedb.com