pqReadData() -- backend closed the channel unexpectedly.

PostgreSQL Bugs List <pgsql-bugs@postgresql.org>

From: pgsql-bugs@postgresql.org
To: pgsql-bugs@postgresql.org
Date: 2001-05-17T17:45:32Z
Lists: pgsql-bugs
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 statement in it enters data in a yyyy variable declared as "RECORD". IF delcared as BOOL, TEXT or INT4, I get the pqReadData error.

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