vscode-sqltools icon indicating copy to clipboard operation
vscode-sqltools copied to clipboard

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

Open bowdi opened this issue 2 years ago • 3 comments

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):

  • SQLTools Version: v0.28.0
  • VS Code Version: 1.81.1
  • OS: Mac
  • Driver:
    • [x] PostgreSQL/Redshift
    • [ ] MySQL/MariaDB
    • [ ] MSSQL/Azure
    • [ ] SQLite
    • [ ] Other? Which...
  • Database version: PostgreSQL v14

bowdi avatar Aug 18 '23 09:08 bowdi

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.

gjsjohnmurray avatar Aug 30 '23 14:08 gjsjohnmurray

Yes correct!

bowdi avatar Sep 04 '23 07:09 bowdi

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

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

gjsjohnmurray avatar Mar 26 '24 16:03 gjsjohnmurray