Subject Re: [firebird-support] Re: order by column alias problem
Author Helen Borrie
At 06:09 PM 20/12/2004 -0500, Ann wrote:

>At 12:20 AM 12/20/2004, Helen Borrie wrote:
>
> > From a logical POV, it doesn't make sense to derive a field just for the
> >purpose of changing its name, since it detaches the output column from the
> >originating column and precludes the use of an index to speed the sorting.
>
>Actually, we ought to be able to map from the alias
>to the field without a great deal of difficulty.

Agreed - in the case where AS is being used just for identifier substitution.



> >There are indications that the standard will deprecate the "by degree"
> >option in future...not sure why...maybe Arno or Ann can answer.
>
>I just had a look at the new standard. It defines the
>ORDER BY clause as ORDER BY <sort specification list>
>which, in turn, is defined like this:
>
> <sort specification list> ::=
> <sort specification> [ { <comma> <sort specification> }... ]
>
> <sort specification> ::=
> <sort key> [ <ordering specification> ] [ <null ordering> ]
>
> <sort key> ::= <value expression>
>
> <ordering specification> ::=
> ASC | DESC
>
> <null ordering> ::=
> NULLS FIRST | NULLS LAST
>
>
>Scary? A sort key is just a value expression, which can be anything.
>I haven't seen any reference to the value expression 1 mapping to the
>first item in the select list, so it may already be deprecated and
>redefined. (They can't do that! or did they? Or both!?)

It looks as if the reaper has already struck. According to Melton (who
wrote the SQL-92 standard -- and, yeah, maybe that's his only creds) --
"IMPORTANT: The ability to use a position number for ordering has been
deprecated in SQL-92, meaning that some future version of SQL might
prohibit it entirely."

>However, it certainly appears to be the case that you could sort by
>an alias. We just need to keep a bit more context (gag) in the
>compiler.

In the same note (in the ORDER BY context), Melton seems to imply this as
well:

"We recommend that you always use the AS clause to give a name to columns
that wouldn't otherwise have a name".

Gotta love 'em.

./h