I have the following 2 functions and I'm getting deadlocks when I call
them from multiple threads. The first, I'm not sure why because I'm
doing a select for update. The second I'm doing an insert on, and I
thought insert will automatically do a lock as it inserts:
-------------FUNCTION 1: -------------
CREATE OR REPLACE FUNCTION
public.select_p end_visitation_ for_unvisited_l inks(int4)
RETURNS SETOF record AS
'
DECLARE
urlrow RECORD;
BEGIN
FOR urlrow in EXECUTE \'SELECT * FROM "URL" WHERE visited=1::int2
LIMIT \' || $1::int4 || \'FOR UPDATE\'
LOOP
UPDATE "URL" SET visited=2 WHERE "URLID"::in t8 =
urlrow."URLID": :int8;
RETURN NEXT urlrow;
END LOOP;
RETURN;
END;
'
LANGUAGE 'plpgsql' VOLATILE;
-------------FUNCTION 2: -------------
CREATE OR REPLACE FUNCTION public.add_link _to_url_table(v archar, int8,
int4, int2, bool, int2)
RETURNS void AS
'
INSERT INTO "URL"
("rootlessURLSt ring","rootURLI D","rootURLIDPa rtition","visit ed",
"createdAt","up datedAt","isVal id","URLType" )
VALUES ($1, $2, $3, $4, now(), now(), $5, $6 );
'
LANGUAGE 'sql' VOLATILE;
Thanx for the help,
amir
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match