development:ohdsi_code_style_for_sql
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| development:ohdsi_code_style_for_sql [2018/02/19 09:10] – schuemie | development:ohdsi_code_style_for_sql [2020/04/06 13:40] (current) – schuemie | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== OHDSI code style for SQL ====== | ====== OHDSI code style for SQL ====== | ||
| - | The OHDSI code style for SQL is heavily inspired by the [[http:// | + | This has moved here: https://ohdsi.github.io/MethodsLibrary/codeStyle.html# |
| - | + | ||
| - | + | ||
| - | ===== Case ===== | + | |
| - | Because several database platforms are case-insensitive and tend to convert table and field names to either uppercase (e.g. Oracle) or lowercase (e.g. PostgreSQL), | + | |
| - | + | ||
| - | **Good** | + | |
| - | + | ||
| - | '' | + | |
| - | + | ||
| - | **Bad** | + | |
| - | + | ||
| - | '' | + | |
| - | + | ||
| - | '' | + | |
| - | + | ||
| - | '' | + | |
| - | + | ||
| - | '' | + | |
| - | + | ||
| - | ===== Commas ===== | + | |
| - | Commas should be trailing. | + | |
| - | + | ||
| - | **Good** | + | |
| - | < | + | |
| - | SELECT COUNT(*) AS person_count, | + | |
| - | condition_concept_id, | + | |
| - | condition_type_concept_id | + | |
| - | FROM condition_era | + | |
| - | GROUP BY condition_concept_id, | + | |
| - | condition_type_concept_id | + | |
| - | </ | + | |
| - | + | ||
| - | **Bad** | + | |
| - | < | + | |
| - | SELECT COUNT(*) AS person_count | + | |
| - | , | + | |
| - | , | + | |
| - | FROM condition_era | + | |
| - | GROUP BY condition_concept_id | + | |
| - | , | + | |
| - | </ | + | |
| - | + | ||
| - | ===== Indentation and new lines ===== | + | |
| - | Indentation is done using tabs. Field definitions are followed by a new line. | + | |
| - | + | ||
| - | **Good** | + | |
| - | < | + | |
| - | SELECT COUNT(*) AS person_count, | + | |
| - | condition_type_concept_id | + | |
| - | FROM ( | + | |
| - | SELECT * | + | |
| - | FROM condition_era | + | |
| - | WHERE condition_concept_id = 123 | + | |
| - | ) tmp | + | |
| - | GROUP BY condition_type_concept_id; | + | |
| - | </ | + | |
| - | + | ||
| - | **Bad** | + | |
| - | < | + | |
| - | SELECT COUNT(*) AS person_count, | + | |
| - | FROM (SELECT * FROM condition_era WHERE condition_concept_id = 123) tmp | + | |
| - | GROUP BY condition_type_concept_id; | + | |
| - | </ | + | |
development/ohdsi_code_style_for_sql.1519031454.txt.gz · Last modified: by schuemie
