Fix example of insert-into w/ nested query
The previous example generated SQL that could not actually execute.
This commit is contained in:
parent
1157887edd
commit
0c3f3d0403
1 changed files with 5 additions and 4 deletions
|
|
@ -117,16 +117,17 @@ The column values do not have to be literals, they can be nested queries:
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
(let [user-id 12345
|
(let [user-id 12345
|
||||||
role-names ["user" "editor"]]
|
role-name "user"]
|
||||||
(-> (insert-into :user_profile_to_role)
|
(-> (insert-into :user_profile_to_role)
|
||||||
(values [{:user_profile_id user-id
|
(values [{:user_profile_id user-id
|
||||||
:role_id (-> (select :id)
|
:role_id (-> (select :id)
|
||||||
(from :role)
|
(from :role)
|
||||||
(where [:in :name role-names]))}])
|
(where [:= :name role-name]))}])
|
||||||
sql/format))
|
sql/format))
|
||||||
|
|
||||||
=> ["INSERT INTO user_profile_to_role (user_profile_id, role_id)
|
=> ["INSERT INTO user_profile_to_role (user_profile_id, role_id)
|
||||||
VALUES (12345, (SELECT id FROM role WHERE (name in (?, ?))))"
|
VALUES (12345, (SELECT id FROM role WHERE name = ?))"
|
||||||
"user" "editor"]
|
"user"]
|
||||||
```
|
```
|
||||||
|
|
||||||
Updates are possible too (note the double S in `sset` to avoid clashing
|
Updates are possible too (note the double S in `sset` to avoid clashing
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue