The snippet library.
Small, practical examples. Search by task or narrow things down below.
Run a first SELECT query
Postgres: Return a literal value without creating a table.
Postgres✓ Tested
Search for a literal LIKE wildcard
Postgres: Declare an escape character so a percent sign in the pattern is literal.
Postgres✓ Tested
Search text without case sensitivity
Match a pattern with PostgreSQL ILIKE.
ILIKE✓ Tested
Select the top row in each group with a tie-breaker
Postgres: Filter an outer query on ROW_NUMBER because window functions are not evaluated in WHERE.
Postgres✓ Tested
Select values in an inclusive range
Postgres: BETWEEN includes both endpoints of the range.
Postgres✓ Tested
Show a group total beside each detail row
Postgres: A partitioned aggregate preserves detail rows instead of collapsing them with GROUP BY.
Postgres✓ Tested
Sort preferred rows ahead of other rows
Postgres: A CASE ordering key expresses business priority before a stable secondary sort.
Postgres✓ Tested
Sort the highest quantities first
Postgres: Specify descending order and a stable tie breaker.
Postgres✓ Tested
Sum a row and its immediate predecessor
Postgres: A ROWS frame counts physical ordered rows rather than all peers with the same sort value.
Postgres✓ Tested
Treat an empty trimmed value as missing
Postgres: NULLIF converts an empty string to NULL before a fallback is applied.
Postgres✓ Tested
Turn a condition into a result label
Postgres: Use CASE to describe stock availability for each row.
Postgres✓ Tested
Turn known group values into columns
Postgres: Conditional aggregation gives a portable pivot when the category set is known.
Postgres✓ Tested