mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.43k stars 291 forks source link

Formatting issues with postgres: format(...), public.* + table_name.* #1202

Open bowdi opened 10 months ago

bowdi commented 10 months ago

Describe the bug When formatting sql files for postgres I've noticed some bugs that cause failures.

  1. When using the postgres format(...) function and dollar quoted strings, format specifiers are separated by a space.
  2. When being explicit about using the public schema in postgres it get's separated by a space.
  3. When using SELECT table_name.* syntax for all columns from a specific table it get's seperated by a space.

To Reproduce Format the following:

SELECT
    -- 1
    FORMAT($$%s %I %L$$, 'hello', 'i''m', 'a string') AS formatted_string,
    -- 2
    public.uuid_generate_v4() AS a_uuid,
    -- 3
    a_table.*
FROM (VALUES ('hello'), ('there')) AS a_table (a_column)

and the output will be:

SELECT -- 1
    FORMAT($$ % s % I % L$$, 'hello', 'i''m', 'a string') AS formatted_string,
    -- 2
    PUBLIC .uuid_generate_v4() AS a_uuid,
    -- 3
    a_table. *
FROM (
        VALUES ('hello'),
            ('there')
    ) AS a_table (a_column)

Expected behaviour

SELECT -- 1
    FORMAT($$ %s %I %L$$, 'hello', 'i''m', 'a string') AS formatted_string,
    -- 2
    public.uuid_generate_v4() AS a_uuid,
    -- 3
    a_table.*
FROM (
        VALUES ('hello'),
            ('there')
    ) AS a_table (a_column)

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

gjsjohnmurray commented 10 months ago

Am I correct in guessing that you have set the language property of the sqltools.format settings object to "pl/sql"? I can reproduce your example with that setting but not when that property isn't defined.

bowdi commented 10 months ago

Yes correct!

gjsjohnmurray commented 3 months ago

Workaround is to disable formatting by setting "sqltools.formatLanguages": [],

Please make sure you restart VS Code after you do this.