postgres-syntax-arrays-ranges
Installation
SKILL.md
postgres-syntax-arrays-ranges
Quick Reference :
PostgreSQL has two native multi-value types that replace ad-hoc string hacks.
Arrays store an ordered list inside one column (int[], text[]). Range
types store an interval ([lower, upper)) as a single value with built-in
overlap and containment logic.
Two rules drive every decision here :
- ALWAYS use a native array instead of a comma-separated string in a
textcolumn. CSV-in-text cannot be indexed, validated, or searched element-wise. - ALWAYS build a GiST index (or an
EXCLUDE USING gistconstraint) before running range-overlap (&&) queries at scale. Without it the planner does a sequential scan on every row.