-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start a SQL style guide #9
Comments
*different SQL variants use different quoting mechanisms :( |
I'm happy to hear input on chutten style: SELECT
DATE_TRUNC('day', DATE_PARSE(field1, '%Y%m%d')) AS pretty_field1,
field2 AS pretty_field2,
FROM table_name
WHERE
field3 IS NOT NULL
AND (
field4 IN ('20180301', '20180302')
OR SUBSTR(field5, 1, 1) = 'a'
)
GROUP BY 1 Notable points I expect contention, and am willing to be swayed, on:
|
+1 to chutten style. Comments:
WHERE field1 IS NOT NULL
AND field2 IS > 10
|
|
@mreid-moz - any argument for indenting table names on the next line? I haven't seen this preference before. Does it add to readability? Make queries easier to write? |
Definitely readability. You end up with the most important SQL keywords on their own lines which makes it very easy to scan for the logical part you're interested in: SELECT
... some stuff
FROM
... some tables
WHERE
... some clauses
GROUP BY
... some groupings
HAVING
... more clauses |
Open question: how to specify the join columns, e.g.
|
|
Here is a list of reserved keywords which should always be capitalized: https://prestodb.io/docs/current/language/reserved.html |
Having to use a CTE just for sensible Also, I contend that CTEs make queries harder to understand, but that might just be me. |
I don't think CTEs should be mandatory either, and IMO |
Seems as though conversation has died out. Shall we omit the controversial subjects (GROUP BY and CTEs) and publish so we don't lose momentum? I'd like to reference a guide when people contribute SQL examples for docs.tmo |
Sounds good to me. @chutten do you have time to take a first pass? |
First pass, open for comments: |
No description provided.
The text was updated successfully, but these errors were encountered: