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] Confusion between LIMIT keyword and column name #302

Open
skubot opened this issue Jul 11, 2022 · 4 comments
Open

[FORMATTING] Confusion between LIMIT keyword and column name #302

skubot opened this issue Jul 11, 2022 · 4 comments

Comments

@skubot
Copy link

skubot commented Jul 11, 2022

We have a table with a 'limit' column, when inserting into the table sql-formatter indents characters after the column name.

Input data
Which SQL and options did you provide as input?
options = { language: 'postgresql' };

Expected Output

INSERT INTO
  search (
    apples,
    limit,
    pears,
    oranges
  )
values
  (
    '__apples',
    '__limit',
    '__pears',
    '__oranges'
  );

Actual Output

INSERT INTO
  search (
    apples,
    limit
      , pears,
    oranges
  )
values
  (
    '__apples',
    '__limit',
    '__pears',
    '__oranges'
  );

Usage

  • How are you calling / using the library?
    calling inside a Jest snapshot-serializer
  • What SQL language(s) does this apply to?
    postgresql
  • Which SQL Formatter version are you using?
    I'm using v8.0.2
@skubot skubot added the bug label Jul 11, 2022
@nene
Copy link
Collaborator

nene commented Jul 11, 2022

Thanks for reporting. Related to #156

This is currently a general issue with how the formatter distinguishes language keywords from identifiers. For the time being there's no quick fix for this. We're working towards a more general solution, though no idea when we'll finally get there.

@nene
Copy link
Collaborator

nene commented Jul 11, 2022

A workaround for the time being is to quote the column name, e.g. "limit".

@skubot
Copy link
Author

skubot commented Jul 13, 2022

@nene Yea in our case we insert using Knex.insert() so it builds the query based on the inputs... so wrapping limit in quotes would be messy.

By the way the latest v8.1.0 changed the result slightly...

INSERT INTO
  search (
    apples,
    limit
      , pears,
    oranges,
    apricots
  )
-- etc...

to...

INSERT INTO
  search (
    apples,
    limit
, pears, --shifted to the left
      oranges, --one indent extra to right
      apricots
  )
-- etc...

@nene
Copy link
Collaborator

nene commented Sep 1, 2022

This issue has gone worse in the latest releases. The above SQL will now produce a hard error:

Parse error at token: , Unexpected COMMA token

The problem being that we're now expecting see LIMIT expr ["," expr].

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