Subject | Re: [firebird-support] Using a query parameter before a subquery |
---|---|
Author | Svein Erling Tysvaer |
Post date | 2007-03-06T11:22:16Z |
I agree that this is an error. I tried a few things that failed at
prepare time:
select count(*)
from rdb$database
where :x < (select count(*) from rdb$database)
select count(*)
from rdb$database
where cast(:x as Integer) < (select count(*) from rdb$database)
And a few things that prepared without problems:
select count(*)
from rdb$database
where (select count(*) from rdb$database) > :x
select count(*)
from rdb$database
where :x < cast((select count(*) from rdb$database) as integer)
I was very surprised to learn that explicitly casting a select count(*)
to integer made the statement prepare, and that's what convinced me that
it is a small error.
I tried this on Firebird 1.5.2, I think (it might have been 1.5.3). I
haven't yet tried it on Firebird 2.0.
Set
Tobias Grimm wrote:
prepare time:
select count(*)
from rdb$database
where :x < (select count(*) from rdb$database)
select count(*)
from rdb$database
where cast(:x as Integer) < (select count(*) from rdb$database)
And a few things that prepared without problems:
select count(*)
from rdb$database
where (select count(*) from rdb$database) > :x
select count(*)
from rdb$database
where :x < cast((select count(*) from rdb$database) as integer)
I was very surprised to learn that explicitly casting a select count(*)
to integer made the statement prepare, and that's what convinced me that
it is a small error.
I tried this on Firebird 1.5.2, I think (it might have been 1.5.3). I
haven't yet tried it on Firebird 2.0.
Set
Tobias Grimm wrote:
> Helen Borrie wrote:
>
>> >SELECT count(*) as y0_ FROM Department this_ WHERE ? < (SELECT count(*)
>> >as y0_ FROM Product this_0_ WHERE this_0_.Department = this_.Number)
>> >But it fails when preparing the query with error code 804.
>> >Is this a bug in Firebird?
>
>> Yes and no, but not really. The ? symbol is a replaceable parameter,
>> not a variable. So a constant in that spot works, whereas a
>> non-typed unknown "thing" doesn't.
>
> I really think, it should work. It's a valid expression, it works with a
> constant on the left or the right side, it works with a parameter on the
> right side and therefore it should also work with a parameter on the
> left side of the subquery.