kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
9.9k stars 249 forks source link

Merge Query joins `WhenNode`s with comma which causes a syntax error #939

Closed gittgott closed 3 months ago

gittgott commented 3 months ago

When you have multiple whens within a merge query, the WhenNodes are joined with a comma. A minimal example of this can be seen in the following kysely playground: https://kyse.link/A9Ndr

The affected lines are as follows (with the comma after @1):

UPDATE SET
  "first_name" = @1,
WHEN NOT MATCHED THEN

I know that this causes a syntax error within mssql, but am not as sure about the other dialects that kysely includes.

I'll make a draft PR shortly in attempt to fix this.