FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
PostgresGetting Started

Run a first SELECT query

Postgres: Return a literal value without creating a table.

Postgres✓ Tested
PostgresText cleanup & matching

Search for a literal LIKE wildcard

Postgres: Declare an escape character so a percent sign in the pattern is literal.

Postgres✓ Tested
PostgresRows & writes

Search text without case sensitivity

Match a pattern with PostgreSQL ILIKE.

ILIKE✓ Tested
PostgresWindow analytics

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
PostgresGetting Started

Select values in an inclusive range

Postgres: BETWEEN includes both endpoints of the range.

Postgres✓ Tested
PostgresWindow analytics

Show a group total beside each detail row

Postgres: A partitioned aggregate preserves detail rows instead of collapsing them with GROUP BY.

Postgres✓ Tested
PostgresSubqueries & ranked selection

Sort preferred rows ahead of other rows

Postgres: A CASE ordering key expresses business priority before a stable secondary sort.

Postgres✓ Tested
PostgresGetting Started

Sort the highest quantities first

Postgres: Specify descending order and a stable tie breaker.

Postgres✓ Tested
PostgresWindow analytics

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
PostgresText cleanup & matching

Treat an empty trimmed value as missing

Postgres: NULLIF converts an empty string to NULL before a fallback is applied.

Postgres✓ Tested
PostgresGetting Started

Turn a condition into a result label

Postgres: Use CASE to describe stock availability for each row.

Postgres✓ Tested
PostgresReporting & grouped calculations

Turn known group values into columns

Postgres: Conditional aggregation gives a portable pivot when the category set is known.

Postgres✓ Tested