-
-
Notifications
You must be signed in to change notification settings - Fork 257
Closed
Description
We have a query that was working fine up until FB 4.0.2. Recently applied patch 4.0.4 and now the query fails with "conversion error from string 'xxx'". I have made a small repro case below except this also exhibits the odd behavior on 4.0.2. Work-arounds follow.
--drop table session$test;
--drop table staff$test;
create table session$test (sess_user char(63));
insert into session$test values ('TEST');
insert into session$test values ('1');
create table staff$test (staffid smallint, primary key (staffid));
insert into staff$test values (1);
select sess.sess_user, stf.staffid
from session$test sess
left join rdb$database rdb
on 1 = 1
left join staff$test stf
on trim(sess.sess_user) similar to '[0-9]+'
and stf.staffid = cast(trim(sess.sess_user) as smallint)
;
SQL Error [335544334] [22018]: conversion error from string "TEST" [SQLState:22018, ISC error code:335544334]
If you run the above you'll get conversion error from string "TEST". Seems to be related to the primary key index causing the parser to prioritize the focus on the 2nd predicate of the 3rd join which is casting the field to SMALLINT.
and stf.staffid = cast(trim(sess.sess_user) as smallint)
Interestingly, by commenting out the 2nd join, the query works fine:
select sess.sess_user, stf.staffid
from session$test sess
-- left join rdb$database rdb
-- on 1 = 1
left join staff$test stf
on trim(sess.sess_user) similar to '[0-9]+'
and stf.staffid = cast(trim(sess.sess_user) as smallint)
;
SESS_USER STAFFID
--------------- ---------
TEST
1 1
And also, preventing usage of the index (stf.staffid+0) also allows the query to work as expected:
select sess.sess_user, stf.staffid
from session$test sess
left join rdb$database rdb
on 1 = 1
left join staff$test stf
on trim(sess.sess_user) similar to '[0-9]+'
and stf.staffid+0 = cast(trim(sess.sess_user) as smallint)
;
SESS_USER STAFFID
--------------- ---------
TEST
1 1