1
0
Fork 0
mirror of https://github.com/treffynnon/sqlstyle.guide.git synced 2025-03-09 12:49:51 -05:00

Add section on booleans

This commit is contained in:
apurvis@lumoslabs.com 2017-02-21 21:57:43 -08:00
parent 23242db50c
commit 97c5032d97

View file

@ -188,7 +188,7 @@ This allows the reader to quickly scan for the important building blocks of the
#### Spaces
Although not exhaustive always include spaces:
Always include spaces:
* before and after equals (`=`)
* after commas (`,`)
@ -244,7 +244,7 @@ WHERE a.title = 'Charcoal Lane'
OR a.title = 'The New Danger';
```
#### Joins
#### JOINs
Joins should be indented 2 spaces right from the `FROM` keyword
@ -269,6 +269,36 @@ FROM riders AS r
WHERE id = 5
```
#### Boolean Expressions
Complicated boolean expressions can be extremely hard to read. To help with this, left justify boolean subclauses
such that the whitespace indicates the current block and the boolean `AND`/`OR` are justified the same as the
expressions they apply to.
```sql
SELECT first_name
FROM rappers
WHERE
(
first_name = 'Mike'
AND
last_name = 'Jones'
)
OR
(
was_tipping = 1
AND
is_still_tippin_on_four_fours = 1
AND
(
is_still_wrapped_in_four_vogues = 1
OR
is_wood_grain_gripping = 0
)
)
```
#### WITH statements (PostgreSQL only)
Indent them until the closing parentheses.