Part 01 / Topic 7 of 10
Anatomy of a SQL statement
Four rules cover almost every beginner stumble:
1. Keywords are not case-sensitive; convention is UPPERCASE. select 1;, SELECT 1; and SeLeCt 1; all work. This course writes keywords in capitals (SELECT, FROM, WHERE) and your own names in lowercase (order_items, unit_price) — the style you will see in almost every real codebase.
2. The semicolon ends the statement. Whitespace and line breaks don't matter, so long statements can spread over many lines for readability:
SELECT
250 * 3 AS total_paise;
total_paise
-------------
750
(1 row)
3. Comments: -- to end of line, /* ... */ for blocks.
-- a comment line
SELECT 2 + 2; -- trailing comment
/* block
comment */
?column?
----------
4
(1 row)
4. Errors are precise — read them. Postgres points at exactly where it got confused:
SELCT 1;
ERROR: syntax error at or near "SELCT"
LINE 1: SELCT 1;
^
The ^ marks the spot. Most "scary" SQL errors are a typo, a missing ;, or a stray comma — the message tells you which.
One more quoting rule you will need soon: to put a single quote inside text, double it:
SELECT 'won''t' AS contraction;
contraction
-------------
won't
(1 row)
🧪 Quick quiz — answer from memory, then check.
- Does SQL care whether you write
selectorSELECT? - How do you write the text
it'sin SQL?
Show the answers
- No — keywords are case-insensitive. The UPPERCASE style is convention for readability.
'it''s'— the doubled quote is a literal single quote.
Done here? The practice set for Part 1 — 6 exercises with solutions — is on the part page.