Re: SELECT is causing a runtime error when used in stored functions: State=42601, Err=7, Msg=ERROR: query has no destination for result data;

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Lothar Bongartz <lbongartz(at)moove(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT is causing a runtime error when used in stored functions: State=42601, Err=7, Msg=ERROR: query has no destination for result data;
Date: 2010-01-16 18:59:57
Message-ID: 4B520CAD.1030908@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 16/01/2010 13:47, Lothar Bongartz wrote:
> State=42601, Err=7, Msg=ERROR: query has no destination for result data;
> Example:
>
> CREATE OR REPLACE FUNCTION MyTest
> (
> IN OUT v_1 int
> ) AS $$BEGIN
> SELECT v_1 = 1;
> END;$$ LANGUAGE plpgsql

The error message says it all - in plpgsql you need to specify a
destination variable for the result of the SELECT.

create....
as
$$
declare
m_result integer;
begin
select 1 into m_result;
return m_result;
end;
$$
language plpgsql;

If you use an OUT parameter as you did in your example, you don't need
the "return m_result;", though you might still need a "return;" to end
the function - not sure on this one.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mathieu De Zutter 2010-01-16 19:40:43 Re: Constraint exclusion issue
Previous Message Scott Marlowe 2010-01-16 18:26:02 Re: Constraint exclusion issue