Let's say I've written plpgsql function that does the following:
CREATE OR REPLACE FUNCTION foobar (_foo_data_id bigint)
RETURNS bigint AS $$
BEGIN
DROP TABLE IF EXISTS tmp_foobar;
CREATE TEMP TABLE tmp_foobar AS
SELECT *
FROM foo_table ft
WHERE ft.foo_data_id = _foo_data_id;
-- more SELECT queries on unrelated tables
-- a final SELECT query that invokes tmp_foobar
END;
First question:
If I simultaneously invoked this function twice, is it possible for the second invocation of foobar()
to drop the tmp_foobar
table while the first invocation of foobar()
is still running?
I understand that SELECT
statements create an ACCESS SHARE
lock, but will that lock persist until the SELECT
statement completes or until the implied COMMIT
at the end of the function?
Second question:
If the latter is true, will the second invocation of foobar()
indefinitely re-try DROP TABLE IF EXISTS tmp_foobar;
until the lock is dropped or will it fail at some point?