Repository navigation
Commit 250f19f
Fix sqlc fmt corruption in PostgreSQL and MySQL formatters (#4596)
Fix six root causes of corruption found by running sqlc fmt across the
endtoend test corpus and verifying the results:
PostgreSQL: a named parameter with a cast (@name::type) printed as
'@ name::type' because the cast binds tighter than the @ operator, so the
printer saw a prefix operator and added a space — silently dropping the
parameter from generated code. Prefix sigils now glue to operands that
start with an identifier.
MySQL (dolphin): the formatter reprinted from the compiler's normalized
AST, which loses information the compiler doesn't need but a formatter
must keep. sqlc fmt now uses a format parser that preserves identifier
case (table names are case-sensitive on most servers), and the converter
keeps what it used to drop:
- NULL, TRUE/FALSE, and decimal literals convert by datum kind, so
NULL no longer prints as '', 1.0 as 0, or true as 1. This also fixes
type inference: a bool literal column is now bool, not int32
(selectstatic golden regenerated).
- SELECT DISTINCT keeps its DISTINCT.
- The ORDER BY of a compound (UNION) statement survives.
- GROUP_CONCAT(... ORDER BY ...) keeps its ordering.
- Optimizer hints (/*+ ... */) are carried through to printing.
- Multi-table UPDATE keeps its JOIN's ON condition and the table
qualifiers in SET.
- DECIMAL(p,s) precision and UNSIGNED survive in column definitions.
Backstop: dolphin now implements Fingerprint (via marino's restore with
identifier case preserved and redundant parens unwrapped), giving MySQL
the same proof PostgreSQL has: fmt accepts a formatted statement only
when it provably means what the author wrote, and otherwise leaves the
statement exactly as written. That is what fixes SHOW WARNINGS, which
the parser rewrites into a synthetic SELECT for analysis: it now falls
back to the original text instead of printing the internal form.
Claude-Session: https://claude.ai/code/session_01UZBvADuHMZEjoF551NccgP
Co-authored-by: Claude <noreply@anthropic.com>1 parent f9f610c commit 250f19f
15 files changed
Lines changed: 369 additions & 76 deletions
File tree
- internal
- cmd
- endtoend/testdata
- fmt
- mysql
- postgresql
- selectstatic/mysql/go
- engine/dolphin
- sql/ast
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | | - | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments