I tried to write a trigger in PostgreSQL 9.1 database, something like:
CREATE FUNCTION test_trigger()
RETURNS trigger AS
BEGIN
IF () THEN INSERT INTO...;
ELSEIF ()...;
...
...
END IF;
RETURN NULL;
END
Then I got this error:
Cannot commit when autoCommit is enabled error
So I tried to disable it using set autocommit=off;
but then got this message:
ERROR: SET AUTOCOMMIT TO OFF is no longer supported
One suggested solution was to use BEGIN
to start a transaction, but I have no idea how to edit my trigger function to do that.
UPDATE
I tried this to disable autocommit with trigger creation as follows:
BEGIN;
CREATE FUNCTION test_trigger()
RETURNS trigger AS
$func$
BEGIN
IF () THEN INSERT INTO...;
ELSEIF ()...;
...
...
END IF;
RETURN NULL;
END
COMMIT;
$func$
LANGUAGE plpgsql;
but the connection closed every time i run this.