sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.37k stars 405 forks source link

[FORMATTING] sqlite UPSERT formatting #783

Closed ulikunitz closed 1 month ago

ulikunitz commented 1 month ago

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

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

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.

Prettier SQL VSCode 1.6

nene commented 1 month ago

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 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.