Bug with FOR ... LOOP and composite types - Mailing list pgsql-bugs

From Oleg Serov
Subject Bug with FOR ... LOOP and composite types
Date
Msg-id cec7c6df0809010503y2d5bd66cua726d4dc853c716d@mail.gmail.com
Whole thread Raw
Responses Re: Bug with FOR ... LOOP and composite types
List pgsql-bugs
Hello.

Seems there is an error when I try to use a table with one field - composite
type, when SELECT QUERY in FOR ... LOOP instruction returns empty result.
Here are steps to reproduce:

CREATE TYPE "t_type" AS (
"a" BIGINT
);

CREATE TABLE"t_table" (
"id" BIGINT NOT NULL,
"t" "t_type",
CONSTRAINT "t_table_pkey" PRIMARY KEY("id")
) WITH OIDS;

CREATE OR REPLACE FUNCTION "t_func" () RETURNS SETOF "t_table" AS
$body$
DECLARE
rec t_table%ROWTYPE;
BEGIN
FOR rec IN
SELECT *
FROM t_table
WHERE 1=0
LOOP
RETURN NEXT rec;
END LOOP;
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

SELECT * FROM t_func()

Result:

ERROR: cannot assign non-composite value to a row variable
CONTEXT: PL/pgSQL function "t_func" line 4 at FOR over SELECT rows

pgsql-bugs by date:

Previous
From: Russell Smith
Date:
Subject: Re: libpq does not manage SSL callbacks properly when other libraries are involved.
Next
From: "Pavel Stehule"
Date:
Subject: Re: Bug with FOR ... LOOP and composite types