Subject Re: Subselects
Author Alexander V.Nevsky
--- In firebird-support@yahoogroups.com, "Bogdan Mugerli"
<mugerlibogdan@e...> wrote:
> Hi
>
> I wonder if the occasional problems with subselects are resolved in
FB1.5 ??
>
> Here is the excerpt from our procedure:
>
> SELECT VALID_FROM, PRICE FROM MATERIALCENA
> WHERE MATERIALid = :IMATERIALID AND VALID_FROM =
> (select max(MC.VALID_FROM from materialcena mc where mc.materialid =
> :imaterialid and mc.VALID_FROM <= 'today')
> INTO :VALID_FROM, :PRICE;
>
> Suddenly subselect didn't return max(valid_from)

Bogdan, this bug is registered in FB tracker and if you were more
attentive, you could avoid it. Change query to

SELECT MC1.VALID_FROM, MC1.PRICE FROM MATERIALCENA MC1
WHERE MC1.MATERIALid = :IMATERIALID AND MC1.VALID_FROM =
(select max(MC.VALID_FROM from materialcena mc where mc.materialid =
MC1.MATERIALid and mc.VALID_FROM <= 'today')

AFAIU this bug is fixed in FB1.5 but fix breaks compatibility with
client-side components which for a long time implemented different
workarounds. So it is decided to make fix optionally turned on/off by
OldParameterOrdering parameter in firebird.conf. Did'nt tried to turn
it on myself. Note proper tables aliases usage in modified query too.

> PS.: this problem should have been solved years ago

Are you ordering?

Best regards,
Alexander.