summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-11-12 10:21:53 +1100
committerCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-11-12 10:21:53 +1100
commit3ea93238b71eb1af0bdfcbab4559c9a6734944e7 (patch)
tree19c0b818fa2130b458d689923a9b855a88f309f1 /README.md
parentedf366e1f31358036c4a43b15f50c10ea80bfd3e (diff)
Fix grouping - it used to allow for groupings leaving a non-grouped field
Now it takes a third "projection" argument in which one can perform aggregate function over the existing fields. The fields of the resulting query are the union of the grouping fields and the projected fields (with the projected fields taking precedence). If you try to project a field without applying some sort of function to it then you'll get an exception, but at the moment no function calls are actually validated as aggregate functions (in order to do so we'd need a knowledge of all the aggregate functions, which isn't possible in general).
Diffstat (limited to 'README.md')
-rw-r--r--README.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/README.md b/README.md
index d29cb5f..4eed172 100644
--- a/README.md
+++ b/README.md
@@ -210,6 +210,29 @@ be the return value of the associated query function call (`deref`,
### 0.2.0
+* **Breaking:** `group` has changed significantly. It now takes a third
+ argument which is an 'auxiliary projection'. The fields in the
+ resulting query will be the union of the grouped fields and the
+ projection (with the projection taking precedence). Each value in
+ the projection must be, in some way, an aggregate of the grouped
+ values (this is not, and cannot really be, enforced, but we try to
+ warn you if you're obviously wrong).
+
+ :::clojure
+ (-> (q/table :users)
+ (q/project [:age :name])
+ (q/group [:age] {'(string_agg :name ",") :names}))
+ ;=> ["SELECT \"users1785\".\"age\" AS \"age\", (\"string_agg\"(\"users1785\".\"name\",?)) AS \"names\"
+ FROM \"users\" AS \"users1785\"
+ GROUP BY \"users1785\".\"age\""
+ ","]
+
+ (-> (q/table :users)
+ (q/project [:age :name])
+ (q/group [:age] {:name :name}))
+ ;=> Exception! Expr is not a function application - could not
+ possible be an aggregate
+
* **Breaking:** Remove `having`, use `select` instead now
* `sort` can now sort on expressions, not just table names