Re: Howto return values from a function

From: "A B" <gentosaker(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Howto return values from a function
Date: 2008-05-16 06:19:27
Message-ID: dbbf25900805152319h27d83715p774cb18f021c70d5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> How you generate the results is up to you. when you have them you
> either use RETURN NEXT or RETURN QUERY to return them to the caller.

Now I get the reply

ERROR: set-valued function called in context that cannot accept a set
CONTEXT: PL/pgSQL function "actionlist" line 11 at return next

and here is the function (and a datatype that is used for the return values)

CREATE TYPE Ttelnr_action AS (
nr VARCHAR(30),
action CHAR(1)
);

CREATE OR REPLACE FUNCTION actionlist(tid_ TIMESTAMP) RETURNS SETOF
Ttelnr_action AS $$
DECLARE
rec RECORD;
result Ttelnr_action;
BEGIN
FOR rec IN SELECT DISTINCT custid,nr,action FROM Actions
LOOP
IF rec.action = 'view_important_message' THEN
result.nr := rec.nr;
result.action := 'd';
RETURN NEXT result;
ELSIF rec.action = 'download_movie' THEN
result.nr := rec.nr;
result.action := 'v';
RETURN NEXT result;
END IF;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2008-05-16 06:32:04 Re: Need for help!
Previous Message Albe Laurenz 2008-05-16 06:17:37 Re: How to create a function with multiple RefCursor OUT parameters