Skip to content

Conversation

@mandarini
Copy link
Contributor

Summary

  • Fix single-object upsert() and insert() to set the columns URL parameter
  • Add defaultToNull option to single-object overloads for consistency
  • Previously only array (bulk) operations set columns, causing single-object upserts to attempt updating ALL table columns, setting missing ones to null

Closes #1653

@github-actions github-actions bot added the postgrest-js Related to the postgrest-js library. label Dec 3, 2025
@mandarini mandarini force-pushed the fix/single-object-upsert-columns branch from 63b053e to 48c84b8 Compare December 3, 2025 12:32
@mandarini mandarini marked this pull request as ready for review December 3, 2025 12:33
@mandarini mandarini requested review from a team as code owners December 3, 2025 12:33
@mandarini mandarini self-assigned this Dec 3, 2025
@coveralls
Copy link

coveralls commented Dec 3, 2025

Coverage Status

coverage: 80.696% (-0.5%) from 81.173%
when pulling 48c84b8 on fix/single-object-upsert-columns
into 8769da9 on master.

@laurenceisla
Copy link
Contributor

laurenceisla commented Dec 4, 2025

The issue #1653 is similar to the one I opened in PostgREST/postgrest#4046, which was closed as not-planned. This is because, for an upsert, it's natural to provide all of the values in the body to insert-or-update a row. So this problem happens because the issue's OP wants to do a bulk update, which is not implemented yet (see PostgREST/postgrest#1959).

They confirm this in the issue (emphasis mine):

I want to bulk update, but must use upsert. I use upsert but receive issues on non-null columns when they are not provided, despite the value existing on the record in the db.

They're forced to use upsert here, but it's not the right tool for this job. I'm afraid the only fix is to make the bulk update work upstream (in PostgREST).

@mandarini
Copy link
Contributor Author

I am closing this PR after discussing with @laurenceisla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postgrest-js Related to the postgrest-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upsert failing on non-null column, even though value exists in db

4 participants