|
1 |
| -# Available operators |
| 1 | +# Available Operators |
2 | 2 |
|
3 |
| -| PostgreSQL operator | Register for DQL as | Implemented by |
| 3 | +## Operator Conflicts and Usage Notes |
| 4 | + |
| 5 | +**⚠️ Important**: Some PostgreSQL operators have multiple meanings depending on the data types involved. This library provides specific DQL function names to avoid conflicts: |
| 6 | + |
| 7 | +| Operator | Array/JSON Usage | Spatial Usage | Text/Pattern Usage | |
| 8 | +|---|---|---|---| |
| 9 | +| `@>` | `CONTAINS` (arrays contain elements) | Works automatically with geometry/geography | N/A | |
| 10 | +| `<@` | `IS_CONTAINED_BY` (element in array) | Works automatically with geometry/geography | N/A | |
| 11 | +| `@` | N/A | `SPATIAL_CONTAINED_BY` (bounding box contained) | N/A | |
| 12 | +| `~` | N/A | `SPATIAL_CONTAINS` (bounding box contains) | `REGEXP` (text pattern matching) | |
| 13 | +| `&&` | `OVERLAPS` (arrays/ranges overlap) | Works automatically with geometry/geography | N/A | |
| 14 | + |
| 15 | +**Usage Guidelines:** |
| 16 | +- **Arrays/JSON**: Use `CONTAINS`, `IS_CONTAINED_BY`, `OVERLAPS` for array and JSON operations |
| 17 | +- **Spatial**: Use `SPATIAL_CONTAINS`, `SPATIAL_CONTAINED_BY` for explicit spatial bounding box operations |
| 18 | +- **Text**: Use `REGEXP`, `IREGEXP` for pattern matching |
| 19 | +- **Boolean operators**: All spatial operators return boolean values and **shall be used with `= TRUE` or `= FALSE` in DQL** |
| 20 | + |
| 21 | +## General Operators |
| 22 | + |
| 23 | +| PostgreSQL operator | Register for DQL as | Implemented by | |
4 | 24 | |---|---|---|
|
5 | 25 | | @> | CONTAINS | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Contains` |
|
6 | 26 | | <@ | IS_CONTAINED_BY | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\IsContainedBy` |
|
|
24 | 44 | | @@ | TSMATCH | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Tsmatch` |
|
25 | 45 | | \|\| | STRCONCAT | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\StrConcat` |
|
26 | 46 |
|
27 |
| -# Available functions |
| 47 | +## PostGIS Spatial Operators |
| 48 | + |
| 49 | +**⚠️ Important**: Some operators have dual meanings for different data types. Use the specific DQL function names to avoid conflicts: |
| 50 | + |
| 51 | +- **`@`**: Use `CONTAINS` for arrays/JSON, `SPATIAL_CONTAINED_BY` for geometry/geography |
| 52 | +- **`~`**: Use `REGEXP` for text patterns, `SPATIAL_CONTAINS` for geometry/geography |
| 53 | +- **`&&`**: Use `OVERLAPS` for arrays/JSON, spatial overlaps work automatically with geometry/geography |
| 54 | + |
| 55 | +**📝 Compatibility Notes**: |
| 56 | +- Most bounding box operators work primarily with **geometry** types |
| 57 | +- **Geography** types have limited operator support (mainly `&&`, `<->`, `<@>`) |
| 58 | +- **3D/n-dimensional operators** may require explicit type casting: `ST_GeomFromText('POINT Z(0 0 0)')` |
| 59 | +- Some advanced operators (`&&&`, `<<#>>`) may not be available in all PostGIS versions |
| 60 | + |
| 61 | +### Bounding Box Operators |
| 62 | + |
| 63 | +These operators work with geometry and geography bounding boxes. All return boolean values and **shall be used with `= TRUE` or `= FALSE` in DQL**. |
| 64 | + |
| 65 | +| PostgreSQL operator | Register for DQL as | Description | Implemented by | |
| 66 | +|---|---|---|---| |
| 67 | +| &< | OVERLAPS_LEFT | Returns TRUE if A's bounding box overlaps or is to the left of B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\OverlapsLeft` | |
| 68 | +| &> | OVERLAPS_RIGHT | Returns TRUE if A's bounding box overlaps or is to the right of B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\OverlapsRight` | |
| 69 | +| << | STRICTLY_LEFT | Returns TRUE if A's bounding box is strictly to the left of B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\StrictlyLeft` | |
| 70 | +| >> | STRICTLY_RIGHT | Returns TRUE if A's bounding box is strictly to the right of B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\StrictlyRight` | |
| 71 | +| @ | SPATIAL_CONTAINED_BY | Returns TRUE if A's bounding box is contained by B's (**spatial version**) | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\SpatialContainedBy` | |
| 72 | +| ~ | SPATIAL_CONTAINS | Returns TRUE if A's bounding box contains B's (**spatial version**) | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\SpatialContains` | |
| 73 | +| ~= | SPATIAL_SAME | Returns TRUE if A's bounding box is the same as B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\SpatialSame` | |
| 74 | +| \|&> | OVERLAPS_ABOVE | Returns TRUE if A's bounding box overlaps or is above B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\OverlapsAbove` | |
| 75 | +| \|>> | STRICTLY_ABOVE | Returns TRUE if A's bounding box is strictly above B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\StrictlyAbove` | |
| 76 | +| &<\| | OVERLAPS_BELOW | Returns TRUE if A's bounding box overlaps or is below B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\OverlapsBelow` | |
| 77 | +| <<\| | STRICTLY_BELOW | Returns TRUE if A's bounding box is strictly below B's | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\StrictlyBelow` | |
| 78 | +| &&& | ND_OVERLAPS | Returns TRUE if A's n-D bounding box intersects B's n-D bounding box | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\NDimensionalOverlaps` | |
| 79 | + |
| 80 | +**Usage Examples:** |
| 81 | +```sql |
| 82 | +-- Find geometries to the left of a reference point |
| 83 | +SELECT e FROM Entity e WHERE STRICTLY_LEFT(e.geometry, 'POINT(0 0)') = TRUE |
| 84 | + |
| 85 | +-- Find overlapping polygons |
| 86 | +SELECT e FROM Entity e WHERE SPATIAL_CONTAINS(e.polygon, e.point) = TRUE |
| 87 | + |
| 88 | +-- 3D spatial relationships |
| 89 | +SELECT e FROM Entity e WHERE ND_OVERLAPS(e.geometry3d, 'POLYGON Z((0 0 0, 1 1 1, 2 2 2, 0 0 0))') = TRUE |
| 90 | +``` |
| 91 | + |
| 92 | +### Distance Operators |
| 93 | + |
| 94 | +These operators calculate distances between geometries. All return numeric values. |
| 95 | + |
| 96 | +| PostgreSQL operator | Register for DQL as | Description | Implemented by | |
| 97 | +|---|---|---|---| |
| 98 | +| <-> | GEOMETRY_DISTANCE | Returns the 2D distance between A and B geometries | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\GeometryDistance` | |
| 99 | +| <@> | DISTANCE | Returns distance between points (legacy operator) | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Distance` | |
| 100 | +| \|=\| | TRAJECTORY_DISTANCE | Returns distance between trajectories at closest point of approach | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TrajectoryDistance` | |
| 101 | +| <#> | BOUNDING_BOX_DISTANCE | Returns the 2D distance between A and B bounding boxes | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BoundingBoxDistance` | |
| 102 | +| <<->> | ND_CENTROID_DISTANCE | Returns n-D distance between centroids of bounding boxes | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\NDimensionalCentroidDistance` | |
| 103 | +| <<#>> | ND_BOUNDING_BOX_DISTANCE | Returns the n-D distance between A and B bounding boxes | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\NDimensionalBoundingBoxDistance` | |
| 104 | + |
| 105 | +**Usage Examples:** |
| 106 | +```sql |
| 107 | +-- Find nearest geometries |
| 108 | +SELECT e, GEOMETRY_DISTANCE(e.geometry, 'POINT(0 0)') as distance |
| 109 | +FROM Entity e ORDER BY distance LIMIT 10 |
| 110 | + |
| 111 | +-- Bounding box distance for index optimization |
| 112 | +SELECT e FROM Entity e WHERE BOUNDING_BOX_DISTANCE(e.geometry, 'POINT(0 0)') < 1000 |
| 113 | + |
| 114 | +-- 3D distance calculations |
| 115 | +SELECT ND_CENTROID_DISTANCE(e.geometry3d1, e.geometry3d2) as distance FROM Entity e |
| 116 | +``` |
| 117 | + |
| 118 | +# Available Functions |
28 | 119 |
|
29 |
| -| PostgreSQL functions | Register for DQL as | Implemented by |
| 120 | +| PostgreSQL functions | Register for DQL as | Implemented by | |
30 | 121 | |---|---|---|
|
31 | 122 | | all | ALL_OF | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\All` |
|
32 | 123 | | any | ANY_OF | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Any` |
|
|
134 | 225 | | width_bucket | WIDTH_BUCKET | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\WidthBucket` |
|
135 | 226 |
|
136 | 227 |
|
137 |
| -# Bonus helpers |
| 228 | +# Bonus Helpers |
138 | 229 |
|
139 |
| -| PostgreSQL functions | Register for DQL as | Implemented by |
| 230 | +| PostgreSQL functions | Register for DQL as | Implemented by | |
140 | 231 | |---|---|---|
|
141 | 232 | | array | ARRAY | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Arr` |
|
142 | 233 | | value = ANY(list of values) | IN_ARRAY | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\InArray` |
|
|
0 commit comments