triggers, transactions and locks - Mailing list pgsql-novice

From Colin Gillespie
Subject triggers, transactions and locks
Date
Msg-id 20DA376D0C991745A4D5249F7BCD7A250D384C@largo.campus.ncl.ac.uk
Whole thread Raw
Responses Re: triggers, transactions and locks
List pgsql-novice
Dear All,

Is there a way to use locks within a trigger? My example below gives the error:
ERROR:  unexpected error -8 in EXECUTE of query "BEGIN"
CONTEXT:  PL/pgSQL function "insert_into_t1" line 6 at execute statement

Thanks

Colin


CREATE FUNCTION insert_into_t1() RETURNS trigger AS'
    DECLARE
        set_qry text;
    BEGIN

        set_qry:=''BEGIN WORK'';
        execute set_qry;
        LOCK t1;
        INSERT INTO t2 VALUES (11);
        COMMIT;
        RETURN NEW;
    END;
' LANGUAGE 'plpgsql' SECURITY DEFINER;

CREATE TRIGGER insert_into_t1 BEFORE INSERT
    ON t1 FOR EACH ROW EXECUTE
        PROCEDURE insert_into_t1();



pgsql-novice by date:

Previous
From: "Vishal Kashyap @ [SaiHertz]"
Date:
Subject: Re: Import .sql file
Next
From:
Date:
Subject: DB start error message