Subject | Re: [firebird-support] Firebird 3, nulls and integer division |
---|---|
Author | Mark Rotteveel |
Post date | 2019-04-19T06:15:36Z |
On 17-4-2019 10:11, Maya Opperman maya@...
[firebird-support] wrote:
tried using (C.YR = :IPeriod / 100)?
you used coalesce(:IPeriod, 0) instead, then this will work because
passing that 0 as second argument will cause Firebird to infer the
parameter correctly as an integer.
The better way would be to use
cast(:IPeriod as integer) / 100
Because this will be able to preserve null values passed.
here, because Firebird needs to determine the types at statement compile
(prepare) time.
regression compared to Firebird 2.5, and otherwise one of the core
developers will be able to tell if this was an intentional change.
Mark
--
Mark Rotteveel
[firebird-support] wrote:
> I am (EVENTUALLY), getting around to upgrading from Firebird 2.5 toIt sounds like the datatype of the parameter can't be inferred. Have you
> Firebird 3.
>
> I purchased the conversion guide, and so far so good, except for this
> problem, which I cannot find a mention of anywhere, no online, nor in
> conversion the guide:
>
> SELECT C.ENDDATE
> FROM CMN_PERIODS C
> WHERE (C.PERIOD = mod(:IPeriod, 100))
> AND (C.YR = (:IPeriod / 100))
>
> The error is:
>
> SQL error state =42000
> Expression evaluation not supported.
> Invalid data type for division in dialect 3
tried using (C.YR = :IPeriod / 100)?
> Eventually, I figured out that this possibly happens on the Firebird 3This will yield a syntax error as coalesce requires two arguments. If
> server when :IPeriod is null, since this now works:
>
> SELECT C.ENDDATE
> FROM CMN_PERIODS C
> WHERE (C.PERIOD = mod(:IPeriod, 100))
> AND (C.YR = (coalesce(:IPeriod) / 100))
you used coalesce(:IPeriod, 0) instead, then this will work because
passing that 0 as second argument will cause Firebird to infer the
parameter correctly as an integer.
The better way would be to use
cast(:IPeriod as integer) / 100
Because this will be able to preserve null values passed.
> BUT, this also works! (ie. Does not give an error)That is expected: any operation on null will yield null.
>
> SELECT C.ENDDATE
> FROM
> CMN_PERIODS C
> WHERE
> (C.PERIOD = mod(:IPeriod, 100))
> AND
> (C.YR = (null / 100))
> I am doing his via FastReports and FIBPlus datasets, so not sure if thatSetting parameter types in the client is - unfortunately - not relevant
> is affecting things. The parameter type is set to Integer.
here, because Firebird needs to determine the types at statement compile
(prepare) time.
> I am going to go ahead and add coalesce to my 20 queries that have thisPlease report it in the tracker. As far as I can see this is a bug and
> in various reports, but would like to know if this is an intended
> side-effect (and my Google-Fu just not good enough to find the relevant
> documentation), and/or if there is some other better way I should be
> dealing with this problem rather (since I am not 100% understanding what
> has changed and why).
regression compared to Firebird 2.5, and otherwise one of the core
developers will be able to tell if this was an intentional change.
Mark
--
Mark Rotteveel