Skip to content

Commit e1bdce9

Browse files
author
Peng Ren
committed
Restrict the superset mode
1 parent 2110cd4 commit e1bdce9

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PyMongoSQL implements the DB API 2.0 interfaces to provide SQL-like access to Mo
2828
- **Nested Structure Support**: Query and filter deeply nested fields and arrays within MongoDB documents using standard SQL syntax
2929
- **SQLAlchemy Integration**: Complete ORM and Core support with dedicated MongoDB dialect
3030
- **SQL Query Support**: SELECT statements with WHERE conditions, field selection, and aliases
31+
- **DML Support (INSERT)**: Insert single or multiple documents using PartiQL object and bag syntax
3132
- **Connection String Support**: MongoDB URI format for easy configuration
3233

3334
## Requirements
@@ -210,6 +211,36 @@ Parameters are substituted into the MongoDB filter during execution, providing p
210211
- LIMIT: `LIMIT 10`
211212
- Combined: `ORDER BY created_at DESC LIMIT 5`
212213

214+
### INSERT Statements
215+
216+
PyMongoSQL supports inserting documents into MongoDB collections using PartiQL-style object and bag literals.
217+
218+
- **Single Document**
219+
220+
```python
221+
cursor.execute("INSERT INTO Music {'title': 'Song A', 'artist': 'Alice', 'year': 2021}")
222+
```
223+
224+
- **Multiple Documents (Bag Syntax)**
225+
226+
```python
227+
cursor.execute(
228+
"INSERT INTO Music << {'title': 'Song B', 'artist': 'Bob'}, {'title': 'Song C', 'artist': 'Charlie'} >>"
229+
)
230+
```
231+
232+
- **Parameterized INSERT (qmark placeholders)**
233+
234+
```python
235+
# Positional parameters using ? placeholders
236+
cursor.execute(
237+
"INSERT INTO Music {'title': '?', 'artist': '?', 'year': '?'}",
238+
["Song D", "Diana", 2020]
239+
)
240+
```
241+
242+
> Note: For INSERT, use positional parameters (`?`). Named placeholders (`:name`) are supported for SELECT queries; INSERT currently recommends `?` style.
243+
213244
## Apache Superset Integration
214245

215246
PyMongoSQL can be used as a database driver in Apache Superset for querying and visualizing MongoDB data:
@@ -233,10 +264,10 @@ This allows seamless integration between MongoDB data and Superset's BI capabili
233264

234265
<h2 style="color: red;">Limitations & Roadmap</h2>
235266

236-
**Note**: Currently PyMongoSQL focuses on Data Query Language (DQL) operations. The following SQL features are **not yet supported** but are planned for future releases:
267+
**Note**: PyMongoSQL focuses on Data Query Language (DQL) operations and selective DML support. The following SQL features are **not yet supported** but are planned for future releases:
237268

238269
- **DML Operations** (Data Manipulation Language)
239-
- `INSERT`, `UPDATE`, `DELETE`
270+
- `UPDATE`, `DELETE`
240271
- **DDL Operations** (Data Definition Language)
241272
- `CREATE TABLE/COLLECTION`, `DROP TABLE/COLLECTION`
242273
- `CREATE INDEX`, `DROP INDEX`

pymongosql/superset_mongodb/executor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def execution_plan(self) -> QueryExecutionPlan:
3737
return self._execution_plan
3838

3939
def supports(self, context: ExecutionContext) -> bool:
40-
"""Support queries with subqueries"""
41-
return context.execution_mode == "superset"
40+
"""Support queries with subqueries, only SELECT statments is supported in this mode."""
41+
normalized = context.query.lstrip().upper()
42+
return "superset" in context.execution_mode.lower() and normalized.startswith("SELECT")
4243

4344
def execute(
4445
self,

0 commit comments

Comments
 (0)