Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit e14461c

Browse files
committed
fix: insert w/ empty body can't have columns param
1 parent 791dc09 commit e14461c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/lib/PostgrestQueryBuilder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
109109

110110
if (Array.isArray(values)) {
111111
const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), [] as string[])
112-
const uniqueColumns = [...new Set(columns)]
113-
this.url.searchParams.set('columns', uniqueColumns.join(','))
112+
if (columns.length > 0) {
113+
const uniqueColumns = [...new Set(columns)]
114+
this.url.searchParams.set('columns', uniqueColumns.join(','))
115+
}
114116
}
115117

116118
return new PostgrestFilterBuilder(this)

test/basic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,8 @@ test('insert includes columns param', async () => {
239239
const client = postgrest.from('users').insert([{ foo: 1 }, { bar: 2 }])
240240
expect((client as any).url.searchParams.get('columns')).toMatchInlineSnapshot(`"foo,bar"`)
241241
})
242+
243+
test('insert w/ empty body has no columns param', async () => {
244+
const client = postgrest.from('users').insert([{}, {}])
245+
expect((client as any).url.searchParams.has('columns')).toBeFalsy()
246+
})

0 commit comments

Comments
 (0)