PostgreSQL Syntax
Expert-level review of raw PostgreSQL SQL syntax in GORM/Go projects. Ensures correct Postgres-specific usage, idiomatic SQL, and avoids common runtime errors.
When to Apply
Use this skill when:
- Writing raw SQL in
db.Raw(),db.Exec(), or migration files - Debugging
syntax errororoperator does not existPostgreSQL errors - Reviewing SQL expressions involving JSONB, UUID, timestamps, or reserved keywords
- Using
RETURNING, CTEs, window functions, orILIKE
Rule Categories
| Priority | Count | Focus |
|---|---|---|
| Critical | 1 | Placeholder style mismatch |
| High | 4 | Identifier quoting, RETURNING, ILIKE, type casting |
| Medium | 4 | CTE readability, JSONB operators, INTERVAL, select redundancy |
Rules Covered (9 total)
Critical Issues (1)
critical-placeholder-style— Use?with GORM,$Nonly with pgx/pq directly
High-Impact Patterns (4)
high-identifier-quoting— Quote reserved keywords (order,user,group) in raw SQLhigh-returning-clause— UseRETURNINGfor generated values after INSERT/UPDATEhigh-ilike-search— UseILIKEfor case-insensitive search, notLOWER(col) LIKEhigh-explicit-cast— Cast types explicitly (::uuid,::bigint) to avoidoperator does not exist
Medium Improvements (4)
medium-cte-readability— Use CTEs instead of nested subqueries for complex queriesmedium-jsonb-operators— Use correct@>,->>,->operators for JSONB queriesmedium-interval-arithmetic— UseINTERVALfor date math, not manual second calculationsmedium-select-redundancy— Don't manually quote plain column names in.Select()(GORM handles it)
Trigger Phrases
- "Check this raw SQL"
- "db.Raw / db.Exec"
- "SQL syntax error"
- "operator does not exist"
- "reserved keyword"
- "JSONB query"
- "PostgreSQL compatibility"
Cross-Reference with golang-best-practices-skill
Two rules in this skill directly extend rules from the companion database-repository skill in golang-best-practices-skill:
| This skill | golang-best-practices-skill | Relationship |
|---|---|---|
high-identifier-quoting |
high-gorm-identifier-quoting |
Expanded — more Postgres examples, full reserved word list |
medium-select-redundancy |
medium-gorm-select-redundancy |
Mirror — same rule, cross-referenced |
Related Skills
- gorm-query-patterns — For ORM-level query patterns
- query-performance — For index-related syntax (CONCURRENTLY, partial indexes)
- migration-safety — For DDL SQL in migration files