[Example 1] create table grp (key int4); insert into grp values(2); insert into grp values(2); create function grup() returns int4 as ' declare k int4; begin select key into k from grp group by key having count(*) > 1; return k; end; ' language 'plpgsql'; select grup(); The result must be grup ---- 2 (1 row) but grup ---- (1 row) [Example 2] create function subsel() returns int4 as ' declare k int4; begin SELECT 1 AS one into k WHERE 1 IN (SELECT 1); return k; end; ' language 'plpgsql'; select subsel(); The result must be subsel ------ 1 (1 row) but pqReadData() -- backend closed the channel unexpectedly. This probably means the backend terminated abnormally before or while processing the request. We have lost the connection to the backend, so further processing is impossible. Terminating.