Insert Join #1646
Unanswered
erwanvivien
asked this question in
Q&A
Insert Join
#1646
Replies: 2 comments
-
|
My correct SQL query would be: INSERT INTO
"Books" (
"user_id",
"name"
)
SELECT
'MY_ID',
'Harry Potter'
WHERE EXISTS (
SELECT 1
FROM "User"
WHERE
"User"."id" = 'MY_ID'
AND "User"."validated" = TRUE
);Which returns When user is not validated |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
It should be possible to build such a query with SeaQuery, or with a raw SQL statement. https://docs.rs/sea-query/latest/sea_query/query/struct.InsertStatement.html#method.select_from |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
I have two tables:
And I would like to assert that user is validated while creating new books.
It allows me to have only one (possibly failing) query instead of two.
https://stackoverflow.com/a/15710598
Proposed Solutions
I don't know
Current Workarounds
Double query. Fetch then insert
Beta Was this translation helpful? Give feedback.
All reactions