inferrinizzard / prettier-sql

[ARCHIVED] Please use https://github.com/sql-formatter-org/sql-formatter
https://github.com/sql-formatter-org/sql-formatter
MIT License
21 stars 5 forks source link

[FORMATTING] Multi-character operators in PostgreSQL syntax are not recognized #54

Open JenChampagne opened 2 years ago

JenChampagne commented 2 years ago

Describe the bug

Multi-character operators in PostreSQL syntax are not recognized.

I prefer to have the denseOperators config set to false so that I can have nice spacing in my SQL for readability. Unfortunately with that configuration set, JSON and JSONB operators go from ->> to - > > which causes PostgreSQL to throw an error stating unexpected >.

More about those operators here: PostgreSQL Docs

Expected Output

Given the following SQL for PostgreSQL:

select
    id,
    data->>'name'
from
    table_with_jsonb_column
;

I expect to format as:

select
    id,
    data ->> 'name'
from
    table_with_jsonb_column
;

Actual Output

What is currently formatted as:

select
    id,
    data - > > 'name'
from
    table_with_jsonb_column
;

Usage

I am using this through the VS Code extension which uses ^5.0.0-beta.1 of this package. I tried to confirm that it was not an issue with the extension as best I could, but apologies if it turns out this is a bug with the extension and not this package.

I believe these operators are likely only for PostreSQL dialects of SQL.

Additional context Add any other context about the problem here.

inferrinizzard commented 2 years ago

Hi @JenChampagne , I believe this issue is resolved as of v5.0.0 but I will double check this before the next release (v5.1.0) + update the package dependency in the VSCode Extension.

Keeping this issue open for now.

inferrinizzard commented 2 years ago

Update: the issue here is regarding the language config in VSCode extension - currently all files are using sql as language, will be patched in upcoming release (v5.1.0)

inferrinizzard commented 2 years ago

@JenChampagne Hi, I have a few additional questions for you:

inferrinizzard commented 2 years ago

VSCode SQL Flavour detection for the Microsoft PostgreSQL and MSSQL Extension is currently not publicly available for other extensions - info request here: https://github.com/microsoft/vscode-mssql/issues/17182

Putting this on hold until I get an answer from the MSSQL repo maintainers (PGSQL repo is dead)

inferrinizzard commented 2 years ago

In the meantime, please use the workaround in #62