2026-10-20 · 6 min read · Rahul Chitturi
- sql
- formatting
- debugging
Flashman's SQL page calls format() with no options. The dialect is the library default, sql, and keyword case is left as you typed it. select stays lowercase. SELECT stays uppercase. A review that expected every keyword to be uppercased is comparing the query with a style the page does not apply.
The visible rewrite is spacing. Some calls gain a space before the opening parenthesis. Others stay tight. Strings and comments stay. A dollar-quoted body does not parse in this dialect.
Separate known calls from unknown calls
now() becomes now () with a space. foo(1) becomes foo (1). nvl(a,b) becomes nvl (a, b). ifnull(a,b) becomes ifnull (a, b). left(a, 2) becomes left (a, 2). date_trunc('day', t) becomes date_trunc ('day', t). The space is inserted because those names are not calls in the default dialect's list.
Names the dialect does know stay tight. count(*) stays count(*). count() and count(1) stay tight. lower(name) stays lower(name). cast(a as int) stays cast(a as int). current_timestamp() stays current_timestamp(). COALESCE(a, b) stays COALESCE(a, b), including the mixed case. extract(day from t) and substring(a from 1 for 2) are broken across lines because they use the special FROM form, and they still have no space before the parenthesis.
- Keep the original query beside the formatted query.
- Treat now () as the formatted form of now().
- Treat count(*) as unchanged.
- Name the dialect when a database accepts a call this page spaces out.
Read the other spacing the same way
a=1 becomes a = 1. in(1,2) becomes in (1, 2). A string is left intact, so 'hello; world' stays one literal and 'it''s' keeps the doubled quote. A line comment and a block comment stay, including a leading /* c */. Two statements separated by a semicolon gain a blank line between them. None of these modes adds a trailing newline after the last token.
Dollar quotes are a parse error. select $tag$ hello; world $tag$ fails with Unexpected "$tag$ hell" and the message names the default sql dialect. The page has no dialect picker, so that error is the result for PostgreSQL dollar quotes. Paste a version that uses ordinary quotes when you only need indentation.
Compare the text the database will see
A box of only spaces returns an empty string before format() runs, so there is no error and no formatted skeleton. A real query that contains spaces inside a string still formats. Copy copies the formatted text, spaces included.
Use the SQL tool to see this spacing, diff to compare it with the statement in the migration, and the regex tester to find call sites in a larger file. Put JSON aside unless the query text is stored in a payload. Quote both the typed call and the formatted call in the ticket, and say that keyword case was preserved.