Tql Prefix

Top's QueryLanguage (TqlRoadmap)

For expressions, if an operation involves 2 tables, such as Join, one can supply "a." and "b." prefixes to column names to distinguish between the first table and the second. If not supplied, the interpreter assumes "a.", meaning the first table.

Does this mean:

For expressions, if an operation involves 2 tables, such as Join, one can optionally supply "a." and "b." prefixes to column names.

What happens if the wrong prefix is used? For example, the query asks for "a.betty", but the "betty" column is only in the second table. Does this cause an error?

What happens if the column exists in neither table? Does this cause an error?

In most languages I know, if an explicit "path" is given (such as "b.foo"), then alternative searching does not take place, and an error is raised if not found at the explicit path.

This rule may seem a little strange, but I want to avoid a "column name-space search" to improve implementation speed, and to reduce the risk of unintended consequences if an overlapping column name is added to participating table(s) after the query is written. We want to reduce the chance that existing queries break simply because new columns are added to existing tables (a frequent ChangePattern).

If a table specifier letter is not given, "a." is assumed. If there is no such column in the first table, an error is raised. One thus knows which table is being referenced without having to look at the table schemas. One can tell just by looking at the query alone without even knowing the schemas. Examples:

  Given      Interpreted as

x = y a.x = a.y x = b.y a.x = b.y x = b.x a.x = b.x b.x = a.x b.x = a.x x = x a.x = a.x (probably not useful in practice)

Because the join syntax has been clarified to default to the first table (even when an unqualified field name is only in the second table), the result line now has fully qualified field names. [ToDo: This needs rewording, -t]

All of the "a." qualifiers are optional. On the other hand, all of the "b." qualifiers are mandatory.


A shortcut to consider for a common idiom is perhaps an asterisk:

  *.xid
Same as:

  a.xid = b.xid

Remember that if two tables have overlapping names, the result table defaults to the first table's column. Note that potential solutions in TqlLacksaNaturalJoin could make this issue void.

--top


CategoryTql, TqlRoadmap


EditText of this page (last edited January 22, 2012) or FindPage with title or text search