Skip site navigation (1) Skip section navigation (2)

Re: [INTERFACES] Function's final statement must be a SELECT

From: "Dave Page" <dpage(at)pgadmin(dot)org>
To: "Premil Agarwal" <preagarw(at)gmail(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org, pgsql-admin(at)postgresql(dot)org
Subject: Re: [INTERFACES] Function's final statement must be a SELECT
Date: 2008-05-14 20:36:13
Message-ID: 937d27e10805141336l601c4aa2x8972c2bd7fda07e6@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-interfaces
On Wed, May 14, 2008 at 9:23 PM, Premil Agarwal <preagarw(at)gmail(dot)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

In response to

Responses

pgsql-admin by date

Next:From: Alvaro HerreraDate: 2008-05-14 20:36:21
Subject: Re: Function's final statement must be a SELECT
Previous:From: Premil AgarwalDate: 2008-05-14 20:23:33
Subject: Function's final statement must be a SELECT

pgsql-interfaces by date

Next:From: Alvaro HerreraDate: 2008-05-14 20:36:21
Subject: Re: Function's final statement must be a SELECT
Previous:From: Premil AgarwalDate: 2008-05-14 20:23:33
Subject: Function's final statement must be a SELECT

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group