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
Copy file name to clipboardExpand all lines: README.md
+37-3Lines changed: 37 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -216,7 +216,9 @@ Parameters are substituted into the MongoDB filter during execution, providing p
216
216
217
217
### INSERT Statements
218
218
219
-
PyMongoSQL supports inserting documents into MongoDB collections using PartiQL-style object and bag literals.
219
+
PyMongoSQL supports inserting documents into MongoDB collections using both PartiQL-style object literals and standard SQL INSERT VALUES syntax.
220
+
221
+
#### PartiQL-Style Object Literals
220
222
221
223
**Single Document**
222
224
@@ -239,12 +241,44 @@ cursor.execute(
239
241
```python
240
242
# Positional parameters using ? placeholders
241
243
cursor.execute(
242
-
"INSERT INTO Music {'title': ?, 'artist': ?, 'year': ?}",
244
+
"INSERT INTO Music {'title': '?', 'artist': '?', 'year': '?'}",
243
245
["Song D", "Diana", 2020]
244
246
)
245
247
```
246
248
247
-
> **Note**: For parameterized INSERT, use positional parameters (`?`). Named placeholders (`:name`) are supported for SELECT, UPDATE, and DELETE queries.
249
+
#### Standard SQL INSERT VALUES
250
+
251
+
**Single Row with Column List**
252
+
253
+
```python
254
+
cursor.execute(
255
+
"INSERT INTO Music (title, artist, year) VALUES ('Song E', 'Eve', 2022)"
256
+
)
257
+
```
258
+
259
+
**Multiple Rows**
260
+
261
+
```python
262
+
cursor.execute(
263
+
"INSERT INTO Music (title, artist, year) VALUES ('Song F', 'Frank', 2023), ('Song G', 'Grace', 2024)"
264
+
)
265
+
```
266
+
267
+
**Parameterized INSERT VALUES**
268
+
269
+
```python
270
+
# Positional parameters (?)
271
+
cursor.execute(
272
+
"INSERT INTO Music (title, artist, year) VALUES (?, ?, ?)",
273
+
["Song H", "Henry", 2025]
274
+
)
275
+
276
+
# Named parameters (:name)
277
+
cursor.execute(
278
+
"INSERT INTO Music (title, artist) VALUES (:title, :artist)",
0 commit comments