Skip to content

Proposal: Format SQL around standalone psql commands - #84

Closed
arnodirlam wants to merge 1 commit into
nene:masterfrom
arnodirlam:codex/psql-command-support
Closed

arnodirlam wants to merge 1 commit into
nene:masterfrom
arnodirlam:codex/psql-command-support

Conversation

@arnodirlam

Copy link
Copy Markdown
Contributor

A proposal for #83: format PostgreSQL between standalone psql commands while preserving the command lines and arguments.

With parser: "psql" and otherwise default options:

Before:

\set ON_ERROR_STOP on
\if :ready
select id,name from widgets where active=true
\gset widget_
\else
  \echo Not ready
  \quit
\endif

After:

\set ON_ERROR_STOP on
\if :ready
SELECT id, name FROM widgets WHERE active = TRUE
\gset widget_
\else
  \echo Not ready
  \quit
\endif

The separate parser makes this opt-in. It never adds final semicolons, even with sqlFinalSemicolon: true, since doing so before \gset could execute the query twice.

This deliberately starts small: unparseable SQL fragments stay as written, including unsupported psql variable interpolation and inline commands. Scripts mentioning COPY remain untouched to protect inline data; that conservative check also catches mentions in comments and strings.

I'd appreciate your thoughts on whether this belongs here or in the underlying parser, and whether preserving unsupported fragments is the right behavior. Feel free to close this PR if it isn't wanted.

@nene

nene commented Sep 22, 2026

Copy link
Copy Markdown
Owner

As explained in #83, I'm rejecting this. The parsing code should live inside a parser.

Also, I'd like to avoid a regex-based parsing approach. I'd really prefer having a proper grammar defined for it.

Additional thing to note is the handling of COPY. This is really a feature missing in the PostgreSQL parser.

@nene nene closed this Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants