Hi there,
I have written a pltcl function which works on one table only and it does on this table a select, then insert or update back to this table conditionally according to the select results. This function would be accessed concurrently, and because result of one call of this function would be affected by previous calls, I wonder how data integrity could be ensured.
I figured a transaction with table locking inside the function would do the job but when I tried to wrap the sql with the following it fails and gives me "SPI_ERROR_TRANSACTION" error:
spi_exec "begin work"
spi_exec "lock table table_name"
spi_exec "select....from table_name"
if {$some_condition} {
spi_exec "insert into table_name ..."
} else {
spi_exec "update table_name ..."
}
spi_exec "commit work"
I was wondering if pltcl functions has its own locking mechanism and would it be safe to use this function concurrently. If not, how should I handle this case?
Thanks for your help in advance.
Sincerely,
Request notifications