Created
December 2, 2010 22:47
-
-
Save bendlas/726251 to your computer and use it in GitHub Desktop.
test case for clojureql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojureql.core) | |
(def users (project (table server/*db* :user_view) | |
[:user_id | |
:lname :fname])) | |
(def groups (aggregate | |
(join (table server/*db* :groups) | |
(table :user_groups) | |
:group_id) | |
[[:array_agg/group_id :as :ids] | |
[:array_agg/label :as :labels]] | |
[:user_groups.user_id])) | |
(def user-groups | |
(outer-join users groups | |
:left :user_id)) | |
(compile user-groups nil) | |
;; gives this; sans formatting | |
; group_subselect.labels --> missing from outer select | |
["SELECT user_view.user_id, user_view.lname, user_view.fname, groups_subselect.ids | |
FROM user_view | |
LEFT OUTER JOIN ( | |
SELECT user_groups.user_id, | |
array_agg(groups.group_id) AS ids, | |
array_agg(groups.label) AS labels | |
FROM groups JOIN user_groups | |
USING (group_id) | |
GROUP BY user_groups.user_id | |
) AS groups_subselect | |
USING(user_id)"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment