Skip to content

Subselect in insert without additional API call #2190

Answered by wolfgangwalther
maxhayward asked this question in Q&A
Discussion options

You must be logged in to vote

There are a couple of different ways to do this:

  • For one, you can just remove the surrogate PK and use the unique names as PKs - and then references them in the mapping table. This will allow you to run the insert on that table directly.
  • Alternatively, you could expose the mapping table as a view - in which you expose those names (instead of or in addition to the IDs). You can then create an insert trigger on that view, which will fetch the IDs when an insert is made with names, but without IDs.
  • You can just create a custom RPC that does the insert.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by wolfgangwalther
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants
Converted from issue

This discussion was converted from issue #2183 on March 10, 2022 11:51.