Hi All,
I am getting ERROR when using the "FOR UPDATE" clause for the partitioned table. below is a reproducible test case for the same.
CREATE TABLE tbl (c1 INT,c2 TEXT) PARTITION BY LIST (c1);
CREATE TABLE tbl_null PARTITION OF tbl FOR VALUES IN (NULL);
CREATE TABLE tbl_1 PARTITION OF tbl FOR VALUES IN (1,2,3);
INSERT INTO tbl SELECT i,i FROM generate_series(1,3) i;
CREATE OR REPLACE FUNCTION func(i int) RETURNS int
AS $$
DECLARE
v_var tbl%ROWTYPE;
cur CURSOR IS SELECT * FROM tbl WHERE c1< 5 FOR UPDATE;
BEGIN
OPEN cur;
LOOP
FETCH cur INTO v_var;
EXIT WHEN NOT FOUND;
UPDATE tbl SET c2='aa' WHERE CURRENT OF cur;
END LOOP;
CLOSE cur;
RETURN 10;
END;
$$ LANGUAGE PLPGSQL;
SELECT func(10);
postgres=# SELECT func(10);
ERROR: cursor "cur" does not have a FOR UPDATE/SHARE reference to table "tbl_null"
CONTEXT: SQL statement "UPDATE tbl SET c2='aa' WHERE CURRENT OF cur"
PL/pgSQL function func(integer) line 10 at SQL statement
Thanks & Regards,
Rajkumar Raghuwanshi