vscode-sql-formatter icon indicating copy to clipboard operation
vscode-sql-formatter copied to clipboard

Inhibit formatting for specific lines?

Open JDeeth opened this issue 3 years ago • 0 comments

I write a lot of SQL queries for SAP BusinessObjects reports. These have a @Prompt expression which allows the statement to take input from the user when it is run. Unfortunately, these only work when the entire expression is on a single line:

WITH "params" AS (
    SELECT
        @Prompt('Username', 'A', , Multi, Free, Persistent, { 'PRODUCT', 'MODEL_OFFICE' }, User:0) :: text as user,
        @Prompt('Date from','D', , Mono, Free, Persistent, , User:1) :: timestamp with time zone at time zone 'UTC' as from_date,
        @Prompt('Date to', 'D', , Mono, Free, Persistent, , User:2) :: timestamp with time zone at time zone 'UTC' as to_date
)
SELECT
    ...

But SQL Formatter will reformat these into a much more sensible multiline presentation, which I then need to change back to single-line.

Is there a feature to make the formatter skip individual lines or sets of lines in the query?

For instance, the black formatter for Python supports # fmt: off and # fmt: on comments:

# fmt: off
custom_formatting = [
    0,  1,  2,
    3,
]
# fmt: on
regular_formatting = [
    0,  1,  2,
    3,
]

black would format the above like this:

# fmt: off
custom_formatting = [
    0,  1,  2,
    3,
]
# fmt: on
regular_formatting = [
    0,
    1,
    2,
    3,
]

JDeeth avatar Oct 20 '22 19:10 JDeeth