@@ -157,14 +157,15 @@ SELECT * FROM Inventory WHERE price > {X} AND amount < {Y}
157
157
### SELECT
158
158
159
159
``` ebnf
160
- SELECT projection FROM relation [ WHERE predicate ]
160
+ SELECT projection FROM relation [ WHERE predicate ] [LIMIT NUM]
161
161
```
162
162
163
163
The query languge is a strict superset of the subscription language.
164
164
The main differences are seen in column projections and [ joins] ( #from-clause ) .
165
165
166
166
The subscription api only supports ` * ` projections,
167
- but the query api supports individual column projections.
167
+ but the query api supports both individual column projections,
168
+ as well as aggregations in the form of ` COUNT ` .
168
169
169
170
The subscription api limits the number of tables you can join,
170
171
and enforces index constraints on the join columns,
@@ -177,11 +178,16 @@ projection
177
178
= '*'
178
179
| table '.' '*'
179
180
| projExpr { ',' projExpr }
181
+ | aggExpr
180
182
;
181
183
182
184
projExpr
183
185
= column [ [ AS ] alias ]
184
186
;
187
+
188
+ aggExpr
189
+ = COUNT '(' '*' ')' [AS] alias
190
+ ;
185
191
```
186
192
187
193
The ` SELECT ` clause determines the columns that are returned.
@@ -196,6 +202,16 @@ SELECT * FROM Inventory;
196
202
SELECT item_name, price FROM Inventory
197
203
```
198
204
205
+ It also allows for counting the number of input rows via the ` COUNT ` function.
206
+ ` COUNT ` always returns a single row, even if the input is empty.
207
+
208
+ ##### Example
209
+
210
+ ``` sql
211
+ -- Count the items in my inventory
212
+ SELECT COUNT (* ) AS n FROM Inventory
213
+ ```
214
+
199
215
#### FROM Clause
200
216
201
217
``` ebnf
@@ -219,6 +235,19 @@ WHERE product.name = {product_name}
219
235
220
236
See [ Subscriptions] ( #where ) .
221
237
238
+ #### LIMIT clause
239
+
240
+ Limits the number of rows a query returns by specifying an upper bound.
241
+ The ` LIMIT ` may return fewer rows if the query itself returns fewer rows.
242
+ ` LIMIT ` does not order or transform its input in any way.
243
+
244
+ ##### Examples
245
+
246
+ ``` sql
247
+ -- Fetch an example row from my inventory
248
+ SELECT * FROM Inventory LIMIT 1
249
+ ```
250
+
222
251
### INSERT
223
252
224
253
``` ebnf
0 commit comments