Skip to content

Commit 14db7d6

Browse files
authored
Document EXCEPT and EXCEPT ALL set operations (#8278)
Adds documentation for the new except() and exceptAll() methods on SelectQuery, covering supported platforms for EXCEPT ALL.
1 parent c124ae6 commit 14db7d6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/en/appendices/5-4-migration-guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ version is reported as `unknown`), the header is omitted.
9999
See [Query Builder](../orm/query-builder#advanced-conditions).
100100
- Added `inOrNull()` and `notInOrNull()` methods for combining `IN` conditions with `IS NULL`.
101101
- Added `isDistinctFrom()` and `isNotDistinctFrom()` methods for null-safe comparisons.
102+
- Added `except()` and `exceptAll()` methods on `SelectQuery` for `EXCEPT`
103+
and `EXCEPT ALL` set operations. `EXCEPT ALL` is supported on PostgreSQL
104+
and recent MySQL/MariaDB versions; it is not supported on SQLite or SQL Server.
105+
See [Query Builder](../orm/query-builder#except).
102106
- Added PostgreSQL index access method reflection. Non-btree indexes (`gin`,
103107
`gist`, `spgist`, `brin`, `hash`) are now reflected with an `accessMethod`
104108
field and regenerated with the correct `USING` clause. The `Index` class

docs/en/orm/query-builder.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,39 @@ $unpublished->intersectAll($inReview);
22002200
`intersect()` and `intersectAll()` were added.
22012201
:::
22022202

2203+
### Except
2204+
2205+
Except operations allow you to return rows from one query that do not appear
2206+
in another query. Except queries are created by composing one or more select
2207+
queries together:
2208+
2209+
```php
2210+
$allArticles = $articles->find();
2211+
2212+
$published = $articles->find()
2213+
->where(['published' => true]);
2214+
2215+
$allArticles->except($published);
2216+
```
2217+
2218+
You can create `EXCEPT ALL` queries using the `exceptAll()` method:
2219+
2220+
```php
2221+
$allArticles = $articles->find();
2222+
2223+
$published = $articles->find()
2224+
->where(['published' => true]);
2225+
2226+
$allArticles->exceptAll($published);
2227+
```
2228+
2229+
`EXCEPT ALL` is supported on PostgreSQL and recent MySQL/MariaDB versions.
2230+
It is not supported on SQLite or SQL Server.
2231+
2232+
::: info Added in version 5.4.0
2233+
`except()` and `exceptAll()` were added.
2234+
:::
2235+
22032236
### Subqueries
22042237

22052238
Subqueries enable you to compose queries together and build conditions and

0 commit comments

Comments
 (0)