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 UPSERT formatting #783

Closed
ulikunitz opened this issue Oct 7, 2024 · 1 comment
Closed

[FORMATTING] sqlite UPSERT formatting #783

ulikunitz opened this issue Oct 7, 2024 · 1 comment
Labels

Comments

@ulikunitz
Copy link

Input data

Which SQL and options did you provide as input?

I use Prettier SQL VSCode with sqlite mode.

insert into  test_table(id, name)
values (1, 'foobar') 
on conflict (id) do update
set name = 'foobar';

Expected Output

insert into
        test_table (id, name)
values
        (1, 'foobar')
on conflict (id) do update
set
        name = 'foobar';

Actual Output

insert into
        test_table (id, name)
values
        (1, 'foobar') on conflict (id) do
update
set
        name = 'foobar';

I suggest to move on conflict (id) do to the next line.

Usage

  • How are you calling / using the library?

I'm using the library with Prettier SQL VS Code and use sqlite mode.

  • What SQL language(s) does this apply to?

Sqlite. Note that sqlite supports multiple on conflict clauses. The syntax is defined here: (https://www.sqlite.org/lang_upsert.html) The page reports that it used the syntax from postfgresql and changed it.

  • Which SQL Formatter version are you using?

Prettier SQL VSCode 1.6

@ulikunitz ulikunitz added the bug label Oct 7, 2024
@nene
Copy link
Collaborator

nene commented Oct 8, 2024

First, please read the FAQ. There's nothing I can do about the Prettier SQL VSCode extension.

However, this bug does partly exist in the latest SQL Formatter library. There are essentially two issues:

  • The ON CONFLICT clause is not printed to a separate line (this is fixed in latest SQL Formatter)
  • The UPDATE in DO UPDATE is recognized as start of an UPDATE statement.

The latter can be easily fixed in SQL Formatter. Though I suggest you give a try to prettier-plugin-sql-cst, which has full support for SQLite, and in general does much better job at formatting SQL.

@nene nene closed this as completed in 381376c Oct 8, 2024
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