Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id EB4642E005C for ; Wed, 14 May 2008 17:38:42 -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 30776-01 for ; Wed, 14 May 2008 17:38:34 -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.184]) by developer.postgresql.org (Postfix) with ESMTP id 3EDA72E0047 for ; Wed, 14 May 2008 17:38:35 -0300 (ADT) Received: by ti-out-0910.google.com with SMTP id y8so51147tia.5 for ; Wed, 14 May 2008 13:38:34 -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=ScuO3JpFumgKJwZ7dTKnvzY+YyiMUro5EZHgT0SYOlQ=; b=gJdKg6pLg7pO6DhQMoUtSH3cjwI8cZMOJAH3yg9QVuZKjcI8JRPHFVb7XKSCfTnoGnuFsxyAmeXVmfdGtMZa3TPd1qEbi9fbRKpjyf5evZWldZIkF/Taj71BSKo0/k2xpFj1H8aGqusOn5sKva5jY9WBqY0DO+YNiNxZsh4oewM= 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=wpyW5TCFlSWnKHgaFJHSlQIAsr9SEln1Paltxyv8SxgW5iXd4lPxder4coLAdgVHROL0KJ9+DV/fGemcbrqT/1yq9l4Gfo9m/NIey0zKCcqaXXoSwjBfMw4xTbRYiR5w6rX1RH0TDNC0Os0e8v46lL+xaj9uNwyueLsMm0S36D0= Received: by 10.150.78.41 with SMTP id a41mr1538743ybb.176.1210797511234; Wed, 14 May 2008 13:38:31 -0700 (PDT) Received: by 10.150.200.17 with HTTP; Wed, 14 May 2008 13:38:31 -0700 (PDT) Message-ID: <92aa956e0805141338p1a496ecdje36e03d8805e5f51@mail.gmail.com> Date: Wed, 14 May 2008 16:38:31 -0400 From: "Premil Agarwal" To: "Dave Page" Subject: Re: [INTERFACES] Function's final statement must be a SELECT Cc: pgsql-interfaces@postgresql.org, pgsql-admin@postgresql.org In-Reply-To: <937d27e10805141336l601c4aa2x8972c2bd7fda07e6@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1249_225311.1210797511249" References: <92aa956e0805141323y3c14fe2p4e10ba9c67637c49@mail.gmail.com> <937d27e10805141336l601c4aa2x8972c2bd7fda07e6@mail.gmail.com> 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/129 X-Sequence-Number: 29213 ------=_Part_1249_225311.1210797511249 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Tried that already, still the same error On Wed, May 14, 2008 at 4:36 PM, Dave Page wrote: > 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 > ------=_Part_1249_225311.1210797511249 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Tried that already, still the same error




On Wed, May 14, 2008 at 4:36 PM, Dave Page <dpage@pgadmin.org> wrote:
On Wed, May 14, 2008 at 9:23 PM, Premil Agarwal <preagarw@gmail.com> 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

------=_Part_1249_225311.1210797511249--