Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 9C56E2E0078; Wed, 14 May 2008 17:36:50 -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 28953-08; Wed, 14 May 2008 17:36:40 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lists.commandprompt.com (host-159.commandprompt.net [207.173.203.159]) by developer.postgresql.org (Postfix) with ESMTP id E54382E006A; Wed, 14 May 2008 17:36:34 -0300 (ADT) Received: from perhan.alvh.no-ip.org (200-126-123-196.bk8-dsl.surnet.cl [200.126.123.196]) (authenticated bits=0) by lists.commandprompt.com (8.13.8/8.13.8) with ESMTP id m4EKbOWZ031756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 May 2008 13:37:27 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 437D447C5E; Wed, 14 May 2008 16:36:21 -0400 (CLT) Date: Wed, 14 May 2008 16:36:21 -0400 From: Alvaro Herrera To: Premil Agarwal Cc: pgsql-interfaces@postgresql.org, pgsql-admin@postgresql.org Subject: Re: Function's final statement must be a SELECT Message-ID: <20080514203621.GI9838@alvh.no-ip.org> References: <92aa956e0805141323y3c14fe2p4e10ba9c67637c49@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <92aa956e0805141323y3c14fe2p4e10ba9c67637c49@mail.gmail.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (lists.commandprompt.com [207.173.203.159]); Wed, 14 May 2008 13:37:27 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/128 X-Sequence-Number: 29212 Premil Agarwal escribió: > 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 $$ [...] > $$ LANGUAGE SQL; ^^^ There's your problem. Try using PLPGSQL instead. In any case, you can do this with COALESCE() and it's much easier. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.