SQL Value Expressions
Value expressions are used in projections, filters, ordering, grouping, and DDL properties.
Common Expression Classes
- Literals: strings, numbers, booleans, nulls, arrays, objects.
- Column references and dereference paths.
- Arithmetic and comparison operators.
- Boolean logic:
AND,OR,NOT. - Function calls (scalar, aggregate, window).
- Casts:
CAST(expr AS type)andexpr::type. - Subqueries and existence checks.
Example
SELECT
id,
amount * 1.18 AS amount_with_tax,
CASE WHEN amount > 1000 THEN 'high' ELSE 'standard' END AS bucket
FROM doc.orders
WHERE customer_id IS NOT NULL
ORDER BY amount DESC;
Notes
- Keep expressions sargable in
WHEREclauses when possible. - Prefer explicit casts in production SQL for stable behavior.
- Use
TRY_CASTwhen ingest quality is uncertain.