Data API Reference: count¶
Syntax¶
Key | Required | Schema | Description |
---|---|---|---|
table | true | TableName | Name of the table |
distinct | false | PGColumn array | Only count the rows with distinct values in these columns |
where | true | BoolExp | Count only the rows where this expression holds true |
Response¶
Key | Always present | Schema | Description |
---|---|---|---|
count | true | Integer | The count of the rows defined by the query |
Description¶
count
returns a count of the rows that satisfy the "where"
condition from the specified table.
If "distinct"
is specified, all duplicate rows are not counted (one row is counted from each group of duplicates).
You must have select
permission on the table and on all the columns used in "where"
and "distinct"
.
Example¶
Count all articles with rating less than 1
curl "$HASURADB_URL/v1/query" \
-X POST \
-H "Authorization: auth_code" \
-H "Content-Type: application/json" \
-d '{ "type" : "count",
"args" : {
"table" : "article", "where" : { "rating" : { "$lt" : 1 } }
}
}'
The response looks like:
{
"count" : 2
}
Was this page helpful?