Cached PL/PGSQL query plan failure

From: "Donald Fraser" <demolish(at)cwgsy(dot)net>
To: "[BUGS]" <pgsql-bugs(at)postgresql(dot)org>
Subject: Cached PL/PGSQL query plan failure
Date: 2004-06-04 14:05:26
Message-ID: 004c01c44a3c$fdc6bd90$1664a8c0@DEMOLITION
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PostgreSQL 7.4.2 on i386-redhat-linux-gnu, compiled by GCC 2.96
OS: Redhat 7.2

Snippet of code which fails:

squery := ''SELECT '' || scolname || '' AS s_data FROM '' || stblname || ''
WHERE id = '' || idrow || '' LIMIT 1'';
FOR data_rec IN EXECUTE squery LOOP
IF (text(sdata) = text(data_rec.s_data)) OR (data_rec.s_data IS NULL AND
sdata IS NULL) THEN
RETURN VOID;
END IF;
END LOOP;

Error message:
ERROR: type of "data_rec.s_data" does not match that when preparing the plan

I get this message if I call the above code once per transaction and the
difference between the transactions is that the data type returned in the
dynamic query is not the same.
I would understand it better if I were calling this piece of code multiple
times with in the one transaction - but I am not.
To over come this problem I had to change the dynamic query as such:

squery := ''SELECT text('' || scolname || '') AS s_data FROM '' || stblname ||
'' WHERE id = '' || idrow || '' LIMIT 1'';
FOR data_rec IN EXECUTE squery LOOP
IF (text(sdata) = data_rec.s_data) OR (data_rec.s_data IS NULL AND sdata IS
NULL) THEN
RETURN VOID;
END IF;
END LOOP;

Regards
Donald Fraser

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-06-04 14:46:40 Re: is array bug? (array[][])[] = NULL
Previous Message Pavel Stehule 2004-06-04 12:50:42 is array bug? (array[][])[] = NULL