Pavel Zotov
unread,Jun 7, 2026, 12:14:50 PM (8 days ago) Jun 7Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to firebird-devel
Cosider script:
======== start ========
set bail on;
set list on;
set autoterm on;
set keep_tran on;
set echo on;
shell if exist r:\temp\tmp4test.fdb del r:\temp\tmp4test.fdb;
create database 'localhost:r:\temp\tmp4test.fdb' user 'sysdba' password 'masterkey';
set autoddl off;
commit;
-- /********************
-- ##############
-- "static" code:
-- ##############
create LOCAL TEMPORARY table ltt_test(f01 int) on commit delete rows;
insert into ltt_test(f01) select i from generate_series(1, 1000) as s(i);
update ltt_test set f01 = -f01 where mod(f01,3) <= 2;
alter table ltt_test alter f01 type int128;
update ltt_test set f01 = 170141183460469231731687303715884105727 where mod(f01,3) = 0;
drop table ltt_test;
create LOCAL TEMPORARY table ltt_test(f01 int) on commit preserve rows;
insert into ltt_test(f01) select i from generate_series(1, 1000) as s(i);
update ltt_test set f01 = -f01 where mod(f01,3) <= 2; -------------------------- [ ! ]
alter table ltt_test alter f01 type int128;
update ltt_test set f01 = 170141183460469231731687303715884105727 where mod(f01,3) = 0;
drop table ltt_test;
exit;
-- *********************/
-- ###############
-- "dynamic" code:
-- ###############
create procedure sp_run_ddl_and_dml_via_es(a_table_name varchar(31), a_index_name varchar(31)) as
declare i smallint;
declare n smallint;
declare v_commit_action varchar(8);
begin
i = 1; --------------------- [ 1 ]
n = 2; --------------------- [ 2 ]
while (i <= n) do
begin
v_commit_action = iif(i = 1, 'DELETE', 'PRESERVE');
execute statement 'create LOCAL TEMPORARY table ' || a_table_name || '(f01 int) on commit ' || v_commit_action || ' rows';
-- execute statement 'create GLOBAL TEMPORARY table ' || a_table_name || '(f01 int) on commit ' || v_commit_action || ' rows';
-- execute statement 'create table ' || a_table_name || '(f01 int)';
execute statement 'insert into ' || a_table_name || '(f01) select i from generate_series(1, 1000) as s(i)';
-- ###################
-- ### N O T E ###
-- ###################
-- execute statement 'update /* ACHTUNG */ ' || a_table_name || ' set f01 = -f01 where mod(f01,3) <= 2';
execute statement 'update /* ACHTUNG: ' || v_commit_action || ' rows */ ' || a_table_name || ' set f01 = -f01 where mod(f01,3) <= 2';
execute statement 'alter table ' || a_table_name || ' alter f01 type int128';
execute statement ('update ' || a_table_name || ' set f01 = ? where mod(f01,3) = ?') (170141183460469231731687303715884105727, 0);
execute statement 'drop table ' || a_table_name;
i = i + 1;
end
end;
commit;
execute block as
begin
execute procedure sp_run_ddl_and_dml_via_es('test_es_1', 'test_es_1_idx');
end
;
exit;
======== finish ========
If we UNcomment block marked as "static code" then script finished OK.
If we remain this block commented and run script as "dynamic" code (i.e. as it is shown) -- also no errors occur.
But if we UNcomment first statement under "### N O T E ###" and Comment out second then weird abend raises:
===============
Statement failed, SQLSTATE = 22003
arithmetic exception, numeric overflow, or string truncation
-Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.
-At procedure "PUBLIC"."SP_RUN_DDL_AND_DML_VIA_ES" line: 38, col: 9
===============
The difference between two statements:
execute statement 'update /* ACHTUNG */ ' || a_table_name || ' set f01 = -f01 where mod(f01,3) <= 2';
vs
execute statement 'update /* ACHTUNG: ' || v_commit_action || ' rows */ ' || a_table_name || ' set f01 = -f01 where mod(f01,3) <= 2';
-- relates only to additional detalization ('v_commit_action') that is "embedded" into the COMMENT that starts with '/* ACHTUNG'.
SAME outcome if we check GTT or permanent table.
Also note that this oddity occurs only when procedure sp_run_ddl_and_dml_via_es contains:
i = 1; --------------------- [ 1 ]
n = 2; --------------------- [ 2 ]
(and not i = 2 & n = 2 or i = 1 and n = 1 -- i.e. TWO iterations must be executed.)
Checked on 6.0.0.1999-c8bc46b.