You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Like we chatted on Gitter, I've added this bit of information.
I tried to maintain the style of the code and SQL to the other examples of the docs. Hope the location is ok, I didn't know where to put it.
Copy file name to clipboardExpand all lines: README.md
+15
Original file line number
Diff line number
Diff line change
@@ -232,6 +232,21 @@ sql`
232
232
update users set "name"= $1, "age"= $2 where user_id = $3
233
233
```
234
234
235
+
### Multiple updates in one query
236
+
It's possible to create multiple udpates in a single query. It's necessary to use arrays intead of objects to ensure the order of the items so that these correspond with the column names.
237
+
```js
238
+
constusers= [
239
+
[1, 'John', 34],
240
+
[2, 'Jane', 27],
241
+
]
242
+
243
+
sql`
244
+
update users set name =update_data.name, age =update_data.age
245
+
from (values${sql(users)}) as update_data (id, name, age)
246
+
whereusers.id=update_data.id
247
+
`
248
+
```
249
+
235
250
### Dynamic values and `where in`
236
251
Value lists can also be created dynamically, making `where in` queries simple too.
0 commit comments