Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres JSON operators not supported when formatting #605

Closed
andy-g opened this issue Jun 4, 2020 · 3 comments
Closed

Postgres JSON operators not supported when formatting #605

andy-g opened this issue Jun 4, 2020 · 3 comments
Assignees

Comments

@andy-g
Copy link

andy-g commented Jun 4, 2020

Describe the bug
Certain special Postgres JSON operators (such as @>) aren't handled by the sqltools formatter and cause the query to become invalid, for example:

SELECT json_col
FROM (
        SELECT '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]' :: jsonb json_col
    ) AS tbl
WHERE json_col @> '[{"c":"baz"}]';

is transformed to the below when formatted (space added between @ & >):

SELECT json_col
FROM (
        SELECT '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]' :: jsonb json_col
    ) AS tbl
WHERE json_col @ > '[{"c":"baz"}]';

To Reproduce
Steps to reproduce the behavior:

  1. Open a new sql file and paste the following query:
    SELECT json_col
    FROM (
            SELECT '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]' :: jsonb json_col
        ) AS tbl
    WHERE json_col @> '[{"c":"baz"}]';
  2. Format the document (or simply save if format on save is configured)
  3. Attempting to execute the query will now result in an error:
    operator does not exist: jsonb @

Expected behavior
The document should be formatted as usual but any special JSON operators (https://www.postgresql.org/docs/current/functions-json.html) should remain valid, and not be split with a space.

Desktop:

  • SQLTools Version: 0.22.4
  • VSCode Version: 1.45.1
  • Driver Used/Version: SQLTools PostgreSQL/Redshift Driver / 0.0.4
  • OS: Mac
@andy-g andy-g added the triage label Jun 4, 2020
@mtxr mtxr self-assigned this Jun 4, 2020
@mtxr mtxr closed this as completed in fd81f7b Jun 5, 2020
@andy-g
Copy link
Author

andy-g commented Jun 5, 2020

That was incredibly fast, thanks so much @mtxr 🙇‍♂️

@mtxr
Copy link
Owner

mtxr commented Jun 5, 2020

I'll release this later today, ok?

@andy-g
Copy link
Author

andy-g commented Jun 5, 2020

Absolutely, I was never expecting you to get to this so quickly. Thanks so much, and thanks for a super valuable extension 👍 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants