This is a draft cheat sheet. It is a work in progress and is not finished yet.
SQL Formatting
Statement |
Format |
Example |
SQL Statement |
UPPERCASE |
|
Tables Views Functions |
snake_case |
|
Indentation |
Tables Columns |
SELECT col, col2, col3 FROM table_name
|
Commas |
Trailing |
Hocon Formatting
Operation |
Do |
Don't |
Interpolated Column Names Keep Within Same File |
pipeline.conf: sql_columns="col1, col2, col3" SELECT {sql_columns} FROM
|
sql_columns.conf: sql_columns="col1, col2, col3" pipeline.conf: SELECT {sql_columns} FROM
|
Concatination of Columns |
pipeline.conf: sql_columns="col1, col2, col3, col4"
SELECT {sql_columns} FROM
|
pipeline.conf: sql_columns_all={ {sql_columns1}, {sql_columns2}}
SELECT {sql_columns_all} FROM
|
Margin & Indents |
sql_query: """ SELECT CREATEDT AS created_date FROM table """
|
sql_query: "SELECT col1 AS column FROM table"
|
Miscellaneous
Comments |
Make comments regarding business logic (GROUP BY, MAX(x), x*100 |
Example: SELECT x_type AS method --Keep for switchboard compatibility
|
Renamings |
Don't Add Underscores to Raw Table Names |
Example: SELECT DEPARTMENTDESC AS department_desc --Keep for switchboard compatibility
|
|
|
SQL Conventions
Operation |
Do |
Don't |
SELECT Explicit |
SELECT column1, column2 FROM table_name
|
|
JOIN Explicit with Alias |
SELECT table_name.column1, table_name.2column2 FROM catalog.schema.table_name AS table_name LEFT JOIN catalog.schema.table_name2 AS table_name2 ON table_name2.site = table_name.site
|
SELECT column1, column2 FROM catalog.schema.table_name JOIN catalog.schema.table_name2 ON catalog.schema.table_name2.site = catalog.schema.table_name.site
|
|