Mark Rotteveel wrote:

> While going over the language reference to do some manual fixes, I came 
> across the following caution (see 
> https://firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-dml-select.html#fblangref25-dml-select-orderby-unions
> 
> """
> Expressions whose calculation results are non-negative integers will be 
> interpreted as column position numbers and will cause an exception if 
> they fall outside the range from 1 to the number of columns.
> 
> Example:
> 
>      SELECT
>        X, Y, NOTE
>      FROM PAIRS
>      ORDER BY X+Y DESC
> 
> 
> * The number returned by a function or a procedure is unpredictable, 
> regardless of whether the sort order is defined by the expression itself 
> or by the column number
> * Only non-negative integers are interpreted as column numbers
> * An integer obtained by one-time evaluation of an expression or by 
> parameter substitution is saved as a constant, because this value 
> applies to all rows.
> """
> 
> I just tested this in Firebird 2.5 and 1.5, and this is not actually the 
> case (and I would be surprised if it ever has been the case). The value 
> of an expression itself is used to sort. As far as I'm aware only 
> literal or parenthesized literal values can be used to identify column 
> positions.
> 
> Any objections if I just remove this caution in the new version?

No, please correct this. I sometimes use expressions for ordering
levels, e.g. with IIF or DECODE constructs that return, say, the
numbers 1, 2 and 3, and they do the expected thing in Fb 2.5 and 3,
i.e. they sort by the numerical value returned, not by the contents
of column 1, 2 or 3.

It would be silly anyway, because the value of X+Y may vary wildly
across rows, so which one would determine the column number
to sort by?

Maybe what they're (trying to) say is true for constant expressions
and/or expressions involving only constants and local variables in
PSQL.

Paul Vinkenoog


_______________________________________________
Firebird-docs mailing list
Firebird-docs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-docs

Reply via email to