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

docs: clarify usage of upsert with surrogate primary keys #3724

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

laurenceisla
Copy link
Member

@laurenceisla laurenceisla commented Sep 14, 2024

Clarify the Upsert docs according to this conversation: #1118 (comment)

Also changed the example to one that uses natural primary keys instead.

@elyobo
Copy link

elyobo commented Sep 15, 2024

An example of how one would do this with surrogate keys as well would probably be helpful.

@wolfgangwalther
Copy link
Member

Is the information in the issue still correct? I remember we added something about handling DEFAULT values instead of NULL for missing values at some point. Maybe that was not for POST in this case?

@laurenceisla
Copy link
Member Author

Is the information in the issue still correct? I remember we added something about handling DEFAULT values instead of NULL for missing values at some point.

Thanks for the heads up, you're absolutely right! e.g. on GENERATED BY DEFAULT... or SERIAL PK columns we can add both preferences Prefer: missing=default, resolution=merge-duplicates and specify the columns to make this work (no need to link the issue anymore). I'll modify accordingly.

Also, I don't see an Upsert spec test that mixes both preferences, I'll add one too.

@laurenceisla laurenceisla merged commit 9c863db into PostgREST:main Nov 15, 2024
23 checks passed
@laurenceisla laurenceisla deleted the docs-upsert-surr branch November 15, 2024 17:05
@laurenceisla
Copy link
Member Author

@elyobo I added an example on what to do with surrogate keys. There is no need for a TRIGGER.

@wolfgangwalther
Copy link
Member

I applied the docs commit on the v12 branch as well. The test commit didn't apply cleanly, didn't bother to fix that.

The docs commit could in theory be back-patched, further, because v11 seems to have missing=default as well - but again, it didn't apply cleanly, so I didn't bother.

At least we have the improved docs on the stable branch right now.

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

Successfully merging this pull request may close these issues.

3 participants