Return Record with CASE problem - Mailing list pgsql-general

From Rory Campbell-Lange
Subject Return Record with CASE problem
Date
Msg-id 20030611135254.GA24986@campbell-lange.net
Whole thread Raw
Responses Re: Return Record with CASE problem
List pgsql-general
Selecting on this function works fine when I don't use the CASE column
'typer' in my select and don't include it in the returned 'resulter' in
the function. 'typer'  is a int2, while the output is a varchar. How can
I get to "typer" in my select?

Failed select:

temporary=> SELECT
                *
            FROM
                fn_v1_board_view_board (1, 1)
            AS (n_id integer, t_description varchar, t_name varchar,
                typer integer, n_id_photo integer);

ERROR:  Query-specified return tuple and actual function return tuple do
not match

Function:

CREATE OR REPLACE FUNCTION fn_v1_board_view_board
    (integer, integer) RETURNS RECORD
    AS '
DECLARE
    boardid                ALIAS for $1;
    personid               ALIAS for $2;
    recone                 RECORD;
    resulter               RECORD;
BEGIN
    SELECT INTO recone
        n_id, t_description, t_name,
        CASE n_type WHEN 0 then ''personal''
                    WHEN 1 then ''private''
                    WHEN 2 then ''blog''
                    ELSE ''public''
        END as typer, n_id_photo
    FROM
        boards
    WHERE
        n_id = boardid;

    IF NOT FOUND THEN
        RAISE EXCEPTION ''board does not exist at fn_v1_board_view_board'';
        SELECT INTO resulter 0,0;
    END IF;

    SELECT INTO resulter
        recone.n_id, recone.t_description, recone.t_name, recone.typer,
        recone.n_id_photo;

    RETURN resulter;

END;'
    LANGUAGE plpgsql;


--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>

pgsql-general by date:

Previous
From: "Jimmie H. Apsey"
Date:
Subject: Re: doing VALID UNTIL programmatically in SQL ?
Next
From: Rory Campbell-Lange
Date:
Subject: Options for select from function returning record?