Thread: pqReadData() -- backend closed the channel unexpectedly.

pqReadData() -- backend closed the channel unexpectedly.

From
pgsql-bugs@postgresql.org
Date:
Kristis Makris (kristis.makris@datasoft.com) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
pqReadData() -- backend closed the channel unexpectedly.

Long Description
Here are the facts:

I have a plpgsql function that should return a value out of a query. The function works when the select xxx into yyyy
statementin it enters data in a yyyy variable declared as "RECORD". IF delcared as BOOL, TEXT or INT4, I get the
pqReadDataerror. 

Here's a snippet of code that exhibits that.

Sample Code
Here's the function declaration when does not work while it should:


CREATE FUNCTION GetCheckNumber(INT4) RETURNS TEXT AS '
DECLARE
    lDepositID ALIAS FOR $1;
    lTemp       TEXT;
BEGIN
    SELECT mc.checknumber
    INTO   lTemp
    FROM   Deposit d,
           MoneyCheck mc
    WHERE  mc.type_id = d.id;

    IF NOT FOUND THEN
       RETURN ''N/A'';
    ELSE
       RETURN lTemp;
    END IF;

END;
'    LANGUAGE 'plpgsql';


And here's a working version of the function using the RECORD type:

CREATE FUNCTION GetCheckNumber(INT4) RETURNS TEXT AS '
DECLARE
    lDepositID ALIAS FOR $1;
    lTemp       RECORD;
BEGIN
    SELECT mc.checknumber
    INTO   lTemp
    FROM   Deposit d,
           MoneyCheck mc
    WHERE  mc.type_id = d.id;

    IF NOT FOUND THEN
       RETURN ''N/A'';
    ELSE
       RETURN lTemp.checknumber;
    END IF;

END;
'    LANGUAGE 'plpgsql';


No file was uploaded with this report

Re: pqReadData() -- backend closed the channel unexpectedly.

From
Tom Lane
Date:
pgsql-bugs@postgresql.org writes:
> Here are the facts:

Postgres version?  Tables needed by the function (declaration and
sample data)?

I tried to reproduce this problem by guessing at a table declaration
and some data, but (unsurprisingly) did not see any problem.  Please
submit a more complete report.

            regards, tom lane