Hello,
I have problem with triggers. There are two triggers: before (abi) and after (aai) insert. The signalled error is in aai with tokens from abi

Both triggers should work separately and should know nothing about each other. I know there are some exceptions when NEXT VALUE cannot be used but it seems it does not cover my problem. What is wrong and how to solve it then?
(environment: db2 9.5 with no patches on Linux)
create table a (i integer)!
create table b (i integer)!
CREATE SEQUENCE sq AS integer!
CREATE TRIGGER abi BEFORE INSERT ON a REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
SET N.i = NEXTVAL FOR sq;
END!
CREATE TRIGGER aai AFTER INSERT ON a REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
insert into b (i)
WITH x(xi) AS (values N.i UNION ALL SELECT xi+1 FROM x WHERE xi<N.i+10)
SELECT xi FROM x;
END!
insert into a values (0)!
Error: SQL0723N An error occurred in a triggered SQL statement in trigger "DB2INST1.AAI". Information returned for the error includes SQLCODE "-348", SQLSTATE "428F9" and message tokens "NEXTVAL FOR DB2INST1.SQ"
If we replace a recursive with simple "insert into b (i) values (n.i);" or remove any trigger it will be working properly. Unfortunately on production I have to have a sequence call before and recursive query after insert.
