Forum OpenACS Q&A: Locking a table inside a PL/PgSQL or PL/Tcl function

Hi all,

Here am I with my PG questions again...

I already found out that I can't have a transaction inside a PL/PgSQL
or PL/Tcl function (AFAIK - I'd be happy to know I am wrong). But is
there a way to lock a table inside a function? Using "lock table
foobar in exclusive mode" does not cause PG to complain, but I don't
know if the table is indeed locked or PG silently ignored my request.

Assuming there's a way to lock a table, would the function need to
finish to release such lock? In the functin where I have "lock
table..." using "commit" or "end" causes PG to puke.

Thanks,

Roberto

I tried a test case of this a while back with the same results that you are seeing.  I think that I've seen this question come up on the pg hackers list before, so you might want to search their archives.  I'm pretty sure that it is broken.