Expressing SQL aliases in jOOQ
SQL aliasing is a simple task. After all, it's just about giving some nicknames to your columns and tables and referring to them via these nicknames instead of using their real names. But as simple as this may seem, this is a rather controversial topic. Some of the open questions you may come across will sound like this: Should I only use aliases when it's mandatory (for instance, when I reference the same table twice)? Should I use meaningful names or will single letters work just fine (p
, q
, t1
, t2
, and so on)? Do they increase readability and decrease typing time? Most probably, the correct answer is that it depends… on the context, on the query, on who is writing the query (a developer, a DBA, a generator), and so on!
As you'll see shortly, using aliasing via a DSL requires us to respect several rules and to be prepared for some verbosity since the host language (here, Java) comes with several shortcomings that a DSL must...