Subject Re: [firebird-support] Order by error in FB 1.5
Author Arno Brinkman
Hi,

> I have a database with a lot of stored procs. I have moved from firebird
> 1.0x to 1.5 and when i try to recompile some stored procs i get the error
> Invalid expression in the ORDER BY clause (not contained in either an
> aggregate function or the GROUP BY clause)

> The expression is

> select max(NFIELD)
> from Table_X
> where IDTABLEX = :IDTableX
> order by IDTABLEX, NFIELD
> into :NField;

> in previous versions i used the order by clause to force index
> selection, but do i have now to change all the metadata to make it
> compatible with 1.5x.

The error is correct, because IDTABLEX isn't a valid field in your query.
The ORDER is done after the aggregate-calculation and at that point there can be more IDTABLEX values for NFIELD.
With other words such a query in FB1.0 could give you wrong results.

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
General database developer support:
http://www.databasedevelopmentforum.com

Firebird open source database (based on IB-OE) with many SQL-99 features:
http://www.firebirdsql.org
http://www.firebirdsql.info

Support list for Interbase and Firebird users:
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep:
news://newsgroups.firebirdsql.info