triggers, transactions and locks

From: "Colin Gillespie" <C(dot)Gillespie(at)newcastle(dot)ac(dot)uk>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: triggers, transactions and locks
Date: 2004-12-06 15:41:07
Message-ID: 20DA376D0C991745A4D5249F7BCD7A250D384C@largo.campus.ncl.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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();

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Keith Worthington 2004-12-06 16:51:29 loading data
Previous Message Felix.Onyango 2004-12-06 14:58:10 DB start error message