File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -194,7 +194,9 @@ export default class PostgrestQueryBuilder<
194
194
* numbers.
195
195
*
196
196
* @param options.defaultToNull - Make missing fields default to `null`.
197
- * Otherwise, use the default value for the column.
197
+ * Otherwise, use the default value for the column. This only applies when
198
+ * inserting new rows, not when merging with existing rows under
199
+ * `ignoreDuplicates: false`.
198
200
*/
199
201
upsert < Row extends Relation extends { Insert : unknown } ? Relation [ 'Insert' ] : never > (
200
202
values : Row | Row [ ] ,
@@ -226,6 +228,14 @@ export default class PostgrestQueryBuilder<
226
228
}
227
229
this . headers [ 'Prefer' ] = prefersHeaders . join ( ',' )
228
230
231
+ if ( Array . isArray ( values ) ) {
232
+ const columns = values . reduce ( ( acc , x ) => acc . concat ( Object . keys ( x ) ) , [ ] as string [ ] )
233
+ if ( columns . length > 0 ) {
234
+ const uniqueColumns = [ ...new Set ( columns ) ] . map ( ( column ) => `"${ column } "` )
235
+ this . url . searchParams . set ( 'columns' , uniqueColumns . join ( ',' ) )
236
+ }
237
+ }
238
+
229
239
return new PostgrestFilterBuilder ( {
230
240
method,
231
241
url : this . url ,
You can’t perform that action at this time.
0 commit comments