$npx -y skills add saifoelloh/golang-best-practices-skill --skill postgresql-syntaxPostgreSQL SQL syntax review for Go/GORM projects. Use when writing or reviewing raw SQL used via db.Raw(), db.Exec(), or migrations. Covers placeholder style, reserved keyword quoting, RETURNING, ILIKE, JSONB operators, and type casting. Don't use for MySQL or SQLite.
| 1 | # PostgreSQL Syntax |
| 2 | |
| 3 | Expert-level review of raw PostgreSQL SQL syntax in GORM/Go projects. Ensures correct Postgres-specific usage, idiomatic SQL, and avoids common runtime errors. |
| 4 | |
| 5 | ## When to Apply |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Writing raw SQL in `db.Raw()`, `db.Exec()`, or migration files |
| 9 | - Debugging `syntax error` or `operator does not exist` PostgreSQL errors |
| 10 | - Reviewing SQL expressions involving JSONB, UUID, timestamps, or reserved keywords |
| 11 | - Using `RETURNING`, CTEs, window functions, or `ILIKE` |
| 12 | |
| 13 | ## Rule Categories |
| 14 | |
| 15 | | Priority | Count | Focus | |
| 16 | |---|---|---| |
| 17 | | Critical | 1 | Placeholder style mismatch | |
| 18 | | High | 4 | Identifier quoting, RETURNING, ILIKE, type casting | |
| 19 | | Medium | 4 | CTE readability, JSONB operators, INTERVAL, select redundancy | |
| 20 | |
| 21 | ## Rules Covered (9 total) |
| 22 | |
| 23 | ### Critical Issues (1) |
| 24 | - `critical-placeholder-style` — Use `?` with GORM, `$N` only with pgx/pq directly |
| 25 | |
| 26 | ### High-Impact Patterns (4) |
| 27 | - `high-identifier-quoting` — Quote reserved keywords (`order`, `user`, `group`) in raw SQL |
| 28 | - `high-returning-clause` — Use `RETURNING` for generated values after INSERT/UPDATE |
| 29 | - `high-ilike-search` — Use `ILIKE` for case-insensitive search, not `LOWER(col) LIKE` |
| 30 | - `high-explicit-cast` — Cast types explicitly (`::uuid`, `::bigint`) to avoid `operator does not exist` |
| 31 | |
| 32 | ### Medium Improvements (4) |
| 33 | - `medium-cte-readability` — Use CTEs instead of nested subqueries for complex queries |
| 34 | - `medium-jsonb-operators` — Use correct `@>`, `->>`, `->` operators for JSONB queries |
| 35 | - `medium-interval-arithmetic` — Use `INTERVAL` for date math, not manual second calculations |
| 36 | - `medium-select-redundancy` — Don't manually quote plain column names in `.Select()` (GORM handles it) |
| 37 | |
| 38 | ## Trigger Phrases |
| 39 | |
| 40 | - "Check this raw SQL" |
| 41 | - "db.Raw / db.Exec" |
| 42 | - "SQL syntax error" |
| 43 | - "operator does not exist" |
| 44 | - "reserved keyword" |
| 45 | - "JSONB query" |
| 46 | - "PostgreSQL compatibility" |
| 47 | |
| 48 | ## Cross-Reference with golang-best-practices-skill |
| 49 | |
| 50 | Two rules in this skill directly extend rules from the companion `database-repository` skill in [golang-best-practices-skill](https://github.com/saifoelloh/golang-best-practices-skill): |
| 51 | |
| 52 | | This skill | golang-best-practices-skill | Relationship | |
| 53 | |---|---|---| |
| 54 | | `high-identifier-quoting` | `high-gorm-identifier-quoting` | Expanded — more Postgres examples, full reserved word list | |
| 55 | | `medium-select-redundancy` | `medium-gorm-select-redundancy` | Mirror — same rule, cross-referenced | |
| 56 | |
| 57 | ## Related Skills |
| 58 | |
| 59 | - [gorm-query-patterns](../gorm-query-patterns/SKILL.md) — For ORM-level query patterns |
| 60 | - [query-performance](../query-performance/SKILL.md) — For index-related syntax (CONCURRENTLY, partial indexes) |
| 61 | - [migration-safety](../migration-safety/SKILL.md) — For DDL SQL in migration files |