-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array distinct unnest ::TEXT[] #53
Comments
What about breaking it down into several operations: SELECT ARRAY(SELECT DISTINCT unnest(tag_list) FROM article ORDER BY 1)::TEXT[] AS tags -- 0. original query
SELECT AS tags -- 1. selectValues
ARRAY( )::TEXT[] -- 2. toTextArray
SELECT DISTINCT unnest(tag_list) FROM article ORDER BY 1 -- 3. use: distict, orderBy
toTextArray
∷ ∀ s
. (∀ z. FullQuery z { x ∷ Col z String })
→ Col s String
toTextArray subQ = Col $ Any do
q ← showQuery subQ
pure $ "ARRAY(" <> q <>")::TEXT[]"
purescript-selda/src/Selda/Query.purs Lines 126 to 129 in aa6047a
purescript-selda/src/Selda/Query.purs Line 157 in aa6047a
I have not tested it myself, but it would be sth that I'd try first. |
I actually tried that before resulting in SELECT
ARRAY (sub_q0.tagList)::text[] AS tagList
FROM ( SELECT DISTINCT
UNNEST(article_0.tag_list) AS tagList
FROM
article article_0
ORDER BY
1 ASC) sub_q0; ERROR: syntax error at or near "sub_q0" |
I'm sorry I meant sth like this: -- SELECT DISTINCT unnest(tag_list) FROM article ORDER BY 1
selectDistinctTagLists = distinct $ selectFrom article \a -> do
let tagList = unnest a.tag_list
orderBy asc tagList -- or `orderBy asc (lit 1)` should work
pure { tagList }
singleton = generate_series 1 1
selectFrom singleton \_ ->
pure
{ tags: toTextArray selectDistinctTagLists
} So that is should be
|
Hi!
I want all tags (array) in every article.
I have tried a bunch of stuff which always results in double
FROM
and::TEXT[]
not in the right place. This non-selda-solution is the best I came up with.If you know something better, let me know.
The text was updated successfully, but these errors were encountered: