FIND YOUR NEXT FEW LINES

The snippet library.

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

125 snippets foundClear filters
PostgresText cleanup & matching

Remove surrounding spaces from text

Postgres: TRIM removes leading and trailing space characters by default.

Postgres✓ Tested
PostgresWindow analytics

Repeat the first ordered value beside each row

Postgres: FIRST_VALUE reads the first value in the current window frame.

Postgres✓ Tested
PostgresText cleanup & matching

Replace a literal substring

Postgres: REPLACE performs a literal replacement rather than a regular-expression substitution.

Postgres✓ Tested
PostgresJSON & arrays

Replace a nested JSONB value

Change one path with jsonb_set.

jsonb_set✓ Tested
PostgresWindows & text

Replace all matching text

Normalize repeated whitespace with a regular expression.

regexp_replace✓ Tested
PostgresSubqueries & ranked selection

Report duplicate business values and their frequency

Postgres: Group by a candidate business key and retain only groups with multiple rows.

Postgres✓ Tested
PostgresConstraints & defaults

Require a value with NOT NULL

Postgres: Declare required fields at the database boundary, not only in application validation.

Postgres✓ Tested
PostgresGetting Started

Require two filtering conditions

Postgres: Combine category and quantity conditions with AND.

Postgres✓ Tested
PostgresSubqueries & ranked selection

Return all rows tied for the maximum in a group

Postgres: An equality comparison with a grouped maximum retains ties rather than choosing one arbitrary row.

Postgres✓ Tested
PostgresRows & writes

Return an inserted row

Read generated data directly from INSERT.

RETURNING✓ Tested
PostgresReporting & grouped calculations

Return zero for a sum over no rows

Postgres: SUM produces NULL for an empty input; COALESCE supplies the desired reporting default.

Postgres✓ Tested
PostgresDates & series

Round a timestamp down to its month

Group dates by a calendar boundary.

date_trunc✓ Tested