Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id CD8262E0031 for ; Wed, 14 May 2008 17:48:04 -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 35731-04 for ; Wed, 14 May 2008 17:47:57 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ti-out-0910.google.com (ti-out-0910.google.com [209.85.142.187]) by developer.postgresql.org (Postfix) with ESMTP id A9AA92E004A for ; Wed, 14 May 2008 17:47:59 -0300 (ADT) Received: by ti-out-0910.google.com with SMTP id y8so61509tia.5 for ; Wed, 14 May 2008 13:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=G6hgwex371STLsYOjTC2lzepOcR+j66wzNEjrUhuduE=; b=cFa4XJ3jswxYAp6Ls6NaHGXfYWmE3qg+Xe1ESYo2xkfr9Y01dX5LKK8xx9XHw76VA85/vU/sxeKwOVlnSfyl0TJjDSerV/eLqvtblNikZUpHpHviIERGp5grVCcmWDrVGE0z308wQBC+w17jg3j6TPph4xx3oejY6uPS/soafhY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=WsQZeLnFsqQrKPhhWQStHLatdCCQtOACZmlpI/0D9sfJpi2JsjjMZkTrDQjde2ApmOek1IG6VRCmhBU//83o38pgjrPFpWAyu2+4kmX06ug6rraDmJ9L+k7jBxZDROUzfF/v6lMHZgkAHZP8wPqZ7IFM/tCmsK19J41gOVc05xU= Received: by 10.150.73.6 with SMTP id v6mr1568934yba.121.1210798075321; Wed, 14 May 2008 13:47:55 -0700 (PDT) Received: by 10.150.200.17 with HTTP; Wed, 14 May 2008 13:47:55 -0700 (PDT) Message-ID: <92aa956e0805141347w2b6f803bq4540c8aa910915e0@mail.gmail.com> Date: Wed, 14 May 2008 16:47:55 -0400 From: "Premil Agarwal" To: "Alvaro Herrera" Subject: Re: Function's final statement must be a SELECT Cc: pgsql-interfaces@postgresql.org, pgsql-admin@postgresql.org In-Reply-To: <20080514203621.GI9838@alvh.no-ip.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1308_17811949.1210798075325" References: <92aa956e0805141323y3c14fe2p4e10ba9c67637c49@mail.gmail.com> <20080514203621.GI9838@alvh.no-ip.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200805/130 X-Sequence-Number: 29214 ------=_Part_1308_17811949.1210798075325 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Great !!! COALESCE() does the job for me. ( BTW, replacing "SQL" by "PLPGSQL " still gets the same error ..... ) Thanks a lot Alvaro !!! On Wed, May 14, 2008 at 4:36 PM, Alvaro Herrera wrote: > Premil Agarwal escribi=F3: > > 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 characte= r > > 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. > ------=_Part_1308_17811949.1210798075325 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Great !!! COALESCE() does the job for me.

( BTW, replacing "SQL= " by "PLPGSQL " still gets the same error ..... )

Tha= nks a lot Alvaro !!!




On Wed, = May 14, 2008 at 4:36 PM, Alvaro Herrera <alvherre@commandprompt.com> wrote:
Premil Agarwal es= cribi=F3:
> 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 su= ch.

>
> CREATE FUNCTION check_for_null( inp character varying) RETURNS charact= er
> 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                 &nbs= p;              http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

------=_Part_1308_17811949.1210798075325--