Re: Lock table in non-volatile functions

From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Lock table in non-volatile functions
Date: 2007-03-17 01:17:10
Message-ID: 45FB4196.9090709@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Gaetano Mendola <mendola(at)bigfoot(dot)com> writes:
>> I'm observing that is not allowed to LOCK a table in a
>> STABLE/IMMUTABLE function but at same time is allowed
>> a SELECT FOR UPDATE.
>
> Really? AFAICS, CommandIsReadOnly() will reject SELECT FOR UPDATE too.

kalman=# select version();
version
--------------------------------------------------------------------------------------------------------
PostgreSQL 8.2.3 on i686-redhat-linux-gnu, compiled by GCC gcc (GCC)
4.1.1 20070105 (Red Hat 4.1.1-51)
(1 row)

kalman=# CREATE TABLE test( a integer );
CREATE TABLE
kalman=# INSERT INTO test VALUES ( 1 );
INSERT 0 1
kalman=# CREATE OR REPLACE FUNCTION sp_test()
kalman-# RETURNS INTEGER AS $body$
kalman$# DECLARE
kalman$# my_integer integer;
kalman$# my_port_set RECORD;
kalman$# BEGIN
kalman$# FOR my_port_set IN
kalman$# SELECT a
kalman$# FROM test
kalman$# FOR UPDATE
kalman$# LOOP
kalman$# my_integer = 0;
kalman$# END LOOP;
kalman$# RETURN 0;
kalman$# END;
kalman$# $body$ language 'plpgsql'
kalman-# STABLE;
CREATE FUNCTION
kalman=# select sp_test();
sp_test
---------
0
(1 row)

BTW why forbid the lock in a non volatile function or (if you fix this)
the SELECT FOR UPDATE ?

Regards
Gaetano Mendola

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-03-17 02:17:34 Re: Lock table in non-volatile functions
Previous Message Tom Lane 2007-03-17 00:46:12 Re: Adding a typmod field to Const et al