Subject | RE: [firebird-support] changed WHERE behavior from fb 1.5 to 2.5 |
---|---|
Author | Svein Erling Tysvær |
Post date | 2011-01-20T12:25:06Z |
> Lets suppose you have this table my_table (code char(1), status smallint):Ok, Anderson, you've shown a case where the order of execution matters, even when the select is from one table only and everything is ANDed (I haven’t seen that before) AND that behaves differently under Firebird 1.5 and 2.5. Though casting a field to integer that can contain a letter is not a great idea anyway, I think I would have rewritten the select statement to either of
>
> --------------
> code | status
> --------------
> 1 | 0
> A | 1
> 2 | 0
> --------------
>
> the following selects give different results
>
> select * from my_table
> where cast(code as integer)=1
> and status=0
>
> select * from my_table
> where status=0
> and cast(code as integer)=1
a) Should work on both Firebird 1.5 and 2.5 as long as code is always numeric when status = 0
select * from my_table
where status=0
and case when status=0 then cast(code as integer) else 0 end = 1
b) should cover all integers and ought to work on Firebird 2.5, though I've never tried (though this will not work on Firebird 1.5)
select * from my_table
where status=0
and iif(code similar to '[[:DIGIT:]*]', cast(code as integer), 0) = 1
HTH,
Set