============================================================================
POSTGRESQL BUG REPORT TEMPLATE
============================================================================
Your name : Adriaan Joubert
Your email address : a.joubert@albourne.com
Category : runtime: back-end
Severity : serious
Summary: Error when using row-level locking from PL
System Configuration
--------------------
Operating System : Alpha DU 4.0D
PostgreSQL version : 6.5
Compiler used : cc
Hardware:
---------
DEC 8200
Versions of other tools:
------------------------
--------------------------------------------------------------------------
Problem Description:
--------------------
I have a PL function that does various things to various tables and needs to lock some rows in one of the tables. But
whenI add 'FOR UPDATE OF <table>' to the SELECT statement, I get the error
ERROR: query didn't return correct # of attributes for *internal*
--------------------------------------------------------------------------
Test Case:
----------
create table a (a int4);
insert into a values (3);
CREATE FUNCTION a_test () RETURNS bool AS
'
DECLARE
mya INT4;
BEGIN
SELECT a INTO mya FROM a;
return true;
END;
' LANGUAGE 'plpgsql';
CREATE FUNCTION b_test () RETURNS bool AS
'
DECLARE
mya INT4;
BEGIN
SELECT a INTO mya FROM a FOR UPDATE OF a;
return true;
END;
' LANGUAGE 'plpgsql';
select a_test();
select b_test();
--------------------------------------------------------------------------
Solution:
---------
--------------------------------------------------------------------------