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

[FORMATTING] SQLite: This doesn't look right #446

Closed
Prinzhorn opened this issue Sep 17, 2022 · 3 comments
Closed

[FORMATTING] SQLite: This doesn't look right #446

Prinzhorn opened this issue Sep 17, 2022 · 3 comments
Labels

Comments

@Prinzhorn
Copy link
Contributor

Input data

Couldn't think of a better title, was just going through my saved queries to see how they would be formatted.

https://sql-formatter-org.github.io/sql-formatter/ defaults with SQLite + uppercase options

SELECT
    foo_bar.value,
    substr(
        decode(content, encoding),
        max(1, foo_bar.start - 20),
        min(length(decode(content, encoding)) - foo_bar.start, end - start + 40)
    ) AS context
FROM view_response_bodies, foo_bar(decode(content, encoding))

Expected Output

Something like this (I guess that depends on the expression width as well):

SELECT
    foo_bar.value,
    substr(
        decode(content, encoding),
        max(1, foo_bar.start - 20),
        min(
            length(decode(content, encoding)) - foo_bar.start,
            end - start + 40
        )
    ) AS context
FROM view_response_bodies, foo_bar(decode(content, encoding))

Actual Output

The comments point to the most obvious things that are broken

SELECT
  foo_bar.value,
  SUBSTR(
    decode (content, encoding), -- SUBSTR is upper case, but not my user-defined decode() function. To be fair, the docs say " and builtin function names to upper or lowercase."
    MAX(1, foo_bar.start - 20),
    MIN(
      LENGTH(decode (content, encoding)) - foo_bar.start,
    END - start + 40 -- end/start are columns of the foo_bar virtual table, don't touch them
    -- Why is this not indented?
  )
) AS context -- shouldn't this be indented one more?
FROM
  view_response_bodies,
  foo_bar (decode (content, encoding))

Usage

https://sql-formatter-org.github.io/sql-formatter/ defaults with SQLite + uppercase options

@Prinzhorn Prinzhorn added the bug label Sep 17, 2022
@nene
Copy link
Collaborator

nene commented Sep 17, 2022

This is another case of the formatter failing to properly distinguish between keywords and identifiers. Duplicate of #156 and #302.

All the indentation issues are just consequences of that underlying issue :(

@Prinzhorn
Copy link
Contributor Author

Looks like other tools suffer from the same issues when not using an actual SQL parser

https://sqlformat.org/
https://sqlparse.readthedocs.io/en/latest/
andialbrecht/sqlparse#631

I was hoping we could draw some inspiration from this package, but it also makes the END/START upper case.

@nene
Copy link
Collaborator

nene commented Sep 20, 2022

Closing this as duplicate.

@nene nene closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants