Thread: Locks in functions?

Locks in functions?

From
Amir Zicherman
Date:
will locks work inside functions or only in transactions?

will this lock? ....

CREATE OR REPLACE FUNCTION public.sample(varchar)
  RETURNS SETOF record AS
'
DECLARE
row RECORD;
BEGIN
LOCK TABLE "URL" IN ROW SHARE MODE;
FOR urlrow in EXECUTE \'SELECT * FROM "table1"\'
LOOP
    UPDATE "table1" SET col1=5 WHERE "col2"=6
    RETURN NEXT row;
END LOOP;
RETURN;
END;
'
  LANGUAGE 'plpgsql' VOLATILE;

thanx, amir