Skip to content

Commit 34523ae

Browse files
feat: add support for Common Table Expressions (CTEs) with UNNEST functionality; update README and increment version to 1.0.1
1 parent b0982c2 commit 34523ae

4 files changed

Lines changed: 434 additions & 2 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Zero-SQL supports a comprehensive set of SQL features:
3939
- **SELECT statements** with column selection, aliases, and DISTINCT
4040
- **Quoted identifiers** (column names with spaces or special characters)
4141
- **FROM clauses** with table references
42+
- **WITH clauses** (Common Table Expressions/CTEs) with UNNEST support
4243
- **JOIN operations** (INNER, LEFT, RIGHT)
4344
- **WHERE clauses** with complex conditions (AND, OR, nested conditions)
4445
- **Comparison operators** (=, !=, >, <, >=, <=, LIKE, ILIKE, IN, NOT IN)
@@ -58,6 +59,9 @@ Zero-SQL supports a comprehensive set of SQL features:
5859
- **LENGTH(text)** / **LEN(text)** - Get string length
5960
- **REPLACE(text, find, replace)** - Replace substrings
6061

62+
### Array Functions
63+
- **UNNEST(array)** - Expand array elements into separate rows (used in CTEs)
64+
6165
### Mathematical Functions
6266
- **ABS(number)** - Absolute value
6367
- **CEIL(number)** - Ceiling (round up)
@@ -336,6 +340,43 @@ Output:
336340
]
337341
```
338342

343+
##### WITH Clause (Common Table Expressions)
344+
345+
```bash
346+
zero-sql "WITH order_items AS (SELECT o._id as order_id, UNNEST(o.items) as item FROM orders o LIMIT 1000) SELECT oi.item.product_id, COUNT(*) as times_ordered FROM order_items oi GROUP BY oi.item.product_id"
347+
```
348+
349+
Output:
350+
```json
351+
[
352+
{
353+
"$unwind": {
354+
"path": "$o.items",
355+
"preserveNullAndEmptyArrays": false
356+
}
357+
},
358+
{
359+
"$project": {
360+
"item": "$o.items",
361+
"order_id": "$order_id"
362+
}
363+
},
364+
{
365+
"$limit": 1000
366+
},
367+
{
368+
"$group": {
369+
"_id": {
370+
"product_id": "$item.product_id"
371+
},
372+
"times_ordered": {
373+
"$sum": 1
374+
}
375+
}
376+
}
377+
]
378+
```
379+
339380
#### GROUP BY with Aggregation
340381

341382
```bash

0 commit comments

Comments
 (0)