question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule for initialisms within FROM clauses.

See original GitHub issue

This is prompted by the excellent work of @piotrgredowski on #473 for #469.

The fishtown sql guide says:

Avoid table aliases in join conditions (especially initialisms) – it’s harder to understand what the table called “c” is compared to “customers”.

Which we have implemented a rule for which corrects:

SELECT u.id, c.first_name, c.last_name, COUNT(o.user_id)
FROM users as u
JOIN customers as c on u.id = c.user_id
JOIN orders as o on u.id = o.user_id

to

SELECT u.id, customers.first_name, customers.last_name, COUNT(orders.user_id)
FROM users as u
JOIN customers on u.id = customers.user_id
JOIN orders on u.id = orders.user_id

This is definitely in line with the letter of the law. What I’m wondering is whether initialisms in a FROM clause are also part of the same antipattern 🤔 . Should there be an additional rule to avoid initialisms in the FROM clause such that the full corrected query is:

SELECT users.id, customers.first_name, customers.last_name, COUNT(orders.user_id)
FROM users
JOIN customers on users.id = customers.user_id
JOIN orders on users.id = orders.user_id

I’m going to ask the fishtown guys what they think, but I’m curious for what other people think.

[I also think that @NiallRees will be amused by this suggestion because he’s seen a load of my production sql and knows that this is one of my bad habits]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
emilieschariocommented, Oct 10, 2020

I’m pretty confident that the answer here is aliases shouldn’t be used for the same reason as you don’t want it in join clauses.

1reaction
NiallReescommented, Oct 11, 2020

I agree that motivation is the same - so I’ll just modify existing rule and reflect this modification in rule documentation. Edit: @NiallRees can you add hacktoberfest label to issue? 😃

From what I’ve read I’m meant to add it to the pull request now but I’ll add to both to make sure! Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Articles (A, An, The) Before Acronyms and Initialisms
An initialism is like an acronym, except you pronounce each letter separately (e.g., “FBI” is short for “Federal Bureau of Investigation” and ...
Read more >
Acronyms and Initialisms - Scribendi
Here are several practical tips to help you use initialisms and acronyms correctly in your writing.
Read more >
abbreviations: acronyms and initialisms - Writing Tips - Termium
As a general rule, use upper-case letters for acronyms or initialisms in their entirety, even if some of the component words or their...
Read more >
8. Punctuation - U.S. Government Publishing Office Style Manual
Before a final clause that extends or amplifies the preceding in- dependent clause. Even if a complete sentence follows the colon, lowercase its...
Read more >
Punctuation Rules - Acronyms and Initialisms - Blog
Initialisms are also made up of letters of some name or term, and also usually with the first letter of each of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found