First, I enabled ON_ERROR_STOP to stop the execution immediately after error as shown below:
\set ON_ERROR_STOP on
Because the doc about ON_ERROR_STOP says below:
By default, command processing continues after an error. When this variable is set to on, processing will instead stop immediately
So, I created test table with num column, then inserted the row whose num is 0 as shown below:
CREATE TABLE test (
num INTEGER
);
INSERT INTO test (num) VALUES (0);
Then, I ran the script which raises INFO error with RAISE statement then, increments num in test table by 1 as shown below. *I also tried RAISE statement with DEBUG, LOG, NOTICE, WARNING, EXCEPTION or nothing:
DO LANGUAGE plpgsql $$
BEGIN
RAISE INFO 'A custom error!';
UPDATE test SET num = num + 1;
END
$$;
But, num was incremented to 1 as shown below. *num was not incremented to 1 only with EXCEPTION or nothing:
postgres=# SELECT num FROM test;
num
-----
1
(1 row)
So, how can I make ON_ERROR_STOP work with RAISE statement properly?
RAISE EXCEPTION.ON_ERROR_STOPdoesn't affect to the behaviour ofINFO,DEBUG,LOG,NOTICEandWARNINGerrors? I mean enablingON_ERROR_STOPdoesn't stopINFO,DEBUG,LOG,NOTICEandWARNINGerrors immediately after error?INFO,DEBUG,LOG,NOTICEandWARNINGwere errors because the doc saysThe level option specifies the error severity.EXCEPTIONis the only one that actually raises an error.