Sql Examples

Page 2 of 7

Browse Sql examples

sqlSnippet

BTree Index Row Size Limit

B-tree entries have a hard row-size ceiling, so an index on an incompressible wide text column builds empty but fails on the first oversized insert.

sqlSnippet

Market Basket Item Pairs

A self-join with a.item < b.item counts unordered item pairs per order, and ORDER BY the pair frequency surfaces the baskets that sell together.

sqlSnippet

Raise Using Errcode And Hint

RAISE ... USING attaches a custom ERRCODE and HINT to a business error, letting callers catch the exact SQLSTATE instead of parsing message text.

sqlSnippet

Top-N Heapsort With LIMIT

A small LIMIT keeps only the top rows in an in-memory heap, which EXPLAIN ANALYZE labels top-N heapsort, instead of fully sorting the table.

sqlSnippet

Btree Deduplicate Items Storage

Create two identical B-tree indexes differing only in deduplicate_items and compare pg_relation_size, showing how PG13 packs duplicate TIDs into posting lists.