Skip to content

alias scoping rules #97

@gavinking

Description

@gavinking

We should introduce a new section specifying the scoping rules for aliases.

OK, so it's perhaps not completely necessary, since the semantics of the language are defined in terms of how operations act on result lists of labeled structure elements, but it's certainly useful, especially for anyone wanting to do any sort of static analysis of the query. (And existing implementations do work by static analysis.)

Without thinking very hard about it, I believe that the rule is nothing more than: a reference to an alias is legal at any point after the alias is declared, with the following wrinkles:

  • the language allows the select clause to come first, instead of near the end, just before order by, but this is easy to deal with, we just say that it is treated as if it occurred in its natural position, and
  • as @beikov has pointed out, the SQL spec has some weird scoping rules around joins, which we missed when we were writing the spec for JPQL all those years ago; rather than trying to reproduce the weird rules, I would just add a note about cases which might not work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions