You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Knex version: 0.95.6
Database + version: PostgreSQL 13
OS: Linux
If issue is about TypeScript definitions, tag @lorefnon
Bug / Maybe Feature request
Explain what kind of behaviour you are getting and how you think it should do
In PostgreSQL it is possible to use expressions in the ON CONFLICT target clause, for instance ON CONFLICT ("name", COALESCE(table_id, -1)). This is particularily useful when wanting to have unique indexes that treat NULL as one specific value (for example CREATE UNIQUE INDEX etst_idx ON public.my_table (id1, coalesce(other_table_id, -1)); This index would not allow duplicate rows with id1 and null
In Knex it is already possibly to create on conflict clauses like that using .onConflict(['id', knex.raw('coalesce(other_table_id, -1)'). This code, intended or not, does create an ON CONFLICT clause that references this index which is very nice! However this is not intended by the Typescript definitions at least, so you have to write as unknown as string otherwise you get the compiler error message below.
Error message
TS error:
The last overload gave the following error.
Type 'Raw<any>' is not assignable to type 'string'.
Reproducer
Works:
knex('my_table').insert([]).onConflict(['my_id', knex.raw('COALESCE(id2,-1)') as unknown as string])
Environment
Knex version: 0.95.6
Database + version: PostgreSQL 13
OS: Linux
If issue is about TypeScript definitions, tag @lorefnon
Bug / Maybe Feature request
In PostgreSQL it is possible to use expressions in the ON CONFLICT target clause, for instance ON CONFLICT ("name", COALESCE(table_id, -1)). This is particularily useful when wanting to have unique indexes that treat NULL as one specific value (for example
CREATE UNIQUE INDEX etst_idx ON public.my_table (id1, coalesce(other_table_id, -1));
This index would not allow duplicate rows with id1 and nullIn Knex it is already possibly to create on conflict clauses like that using
.onConflict(['id', knex.raw('coalesce(other_table_id, -1)')
. This code, intended or not, does create an ON CONFLICT clause that references this index which is very nice! However this is not intended by the Typescript definitions at least, so you have to writeas unknown as string
otherwise you get the compiler error message below.TS error:
Works:
Doesnt Work:
The text was updated successfully, but these errors were encountered: