Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected behavior with defaultToNull set to true in bulk inserts #1223

Open
1 of 2 tasks
devpulse01 opened this issue Jun 14, 2024 · 1 comment
Open
1 of 2 tasks

Expected behavior with defaultToNull set to true in bulk inserts #1223

devpulse01 opened this issue Jun 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@devpulse01
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When performing bulk inserts using the Supabase JS client with the defaultToNull option,
the behavior of handling missing columns seems to vary based on the presence of the
column in other rows within the same payload.

To Reproduce

Payload with mixed presence of "name" column:

const payload = [
  { category_id: 'a9278bf3' },
  { name: 'MyTask', category_id: 'a9278bf3' }
];

With defaultToNull: true: the first row has the "name" set to null as expected.


Payload with consistently missing "name" Column:

const payload = [
  { category_id: 'a9278bf3' },
  { category_id: 'a9278bf3' }
];

With defaultToNull: true: both rows use the column's default value for the "name" column and not null.

Expected behavior

Is this behavior expected when using the defaultToNull option in bulk inserts?

Specifically, should missing columns be inserted as null only if at least one row in the payload specifies the column?

System information

  • Version of supabase-js: 2.43.4

Thank you!

@devpulse01 devpulse01 added the bug Something isn't working label Jun 14, 2024
@leohanon
Copy link

leohanon commented Aug 8, 2024

This is a PostgREST thing, not a supabase-js one. And yeah that's the way they handle it.

if you UPSERT or INSERT an INDIVIDUAL record, the record's missing values will ALWAYS try to get filled in with the database's default values.

if you UPSERT or INSERT a GROUP of records, the same exact thing happens... BUT the "missing values" are whatever missing columns are missing on ALL records that you're sending.

defaultToNull applies ONLY to values that are missing on SOME records and NOT others. If you're leaving them out on some records and not others PostgREST will think you MEANT to leave them out, so it treats them as NULL. With defaultToNull set to FALSE you're saying "if I leave anything out, fill it in with default values"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants