Skip to content

SQL formatter breaks DB-API pyformat placeholders (%(param)s) #1724

@miomelliot

Description

@miomelliot

Hi! 👋
First of all, thank you for this extension — it’s very useful.

I’ve noticed an issue with SQL formatting when using Python DB-API
drivers such as psycopg / psycopg3.


Problem

The formatter automatically rewrites DB-API pyformat placeholders:

%(end_date)s

into:

% (end_date) s

This breaks SQL execution completely, because %(param)s is a valid and
widely used placeholder format in Python database drivers
(psycopg2 / psycopg3).

This happens even when VS Code formatOnSave is disabled for SQL,
so it seems to be done internally by the Database Client formatter.


Why this matters

%(param)s is not a SQL operator — it is a parameter placeholder
defined by Python DB-API (PEP 249) and is extremely common in:

  • ETL / analytics projects
  • psycopg3
  • SQLAlchemy Core (text queries)
  • Airflow / custom SQL pipelines

Automatically inserting spaces makes valid queries unusable.


Feature request / suggestion

It would be great to have one of the following:

  1. An option to disable formatting of %( )s patterns
  2. An option to disable SQL formatting on save entirely
  3. A PostgreSQL / DB-API–aware mode that preserves %(param)s

Even a simple toggle like:

database-client.sqlFormatter.preservePyFormat: true

would fully solve the issue.


Temporary workaround

Right now the only workaround is to avoid %(...)s in SQL files or
disable the extension, which is unfortunate.


Thanks again for the great extension, and I hope this can be improved 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions