Comments (3)
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
FROM generate_series(1,1)
because we do selectFrom singleton
and the nested query should be between ARRAY (
and )::text[]
and no subquery alias should appear
AS tags
appears because I named it so after the pure
from purescript-selda.
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
selectValues
#46
I'll provide this function after we mergescope-as-backend
, for now, consider the workaround:
- create a dummy table
singleton
that contains just one value (e.g. usegenerate_series 1 1
) selectValues r = selectFrom singleton \_ -> r
toTextArray
should take a query with just one column (of type String, right?) and wrap it withARRAY( ... ):TEXT[]
treating it as a DB expressionCol s String
toTextArray
∷ ∀ s
. (∀ z. FullQuery z { x ∷ Col z String })
→ Col s String
toTextArray subQ = Col $ Any do
q ← showQuery subQ
pure $ "ARRAY(" <> q <>")::TEXT[]"
SELECT DISTINCT unnest(tag_list) FROM article ORDER BY 1
this query should be expressible in selda,distinct
andorderBy
are available,unnest(_)
implement like a custom pg function from the guide
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 hope it helps!
from purescript-selda.
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"
LINE 1: SELECT ARRAY (sub_q0.tagList)::TEXT[] AS tagList
from purescript-selda.
Related Issues (20)
- Problem with "pg": "^7.6.0" in package.json
- Question about data intermediate representations HOT 9
- Auto field gets updated HOT 7
- Update returning similar to insert returning
- Easier logging of the update, insert ...
- SELECT values without FROM clause
- Better type inference for insert
- Delete returning
- IS NOT NULL as SQL expression not query needed HOT 4
- `offset` clause missing
- Select Count (*) error HOT 11
- good first issues/bugs
- Nested structures/ JSON HOT 2
- Update to be compatible on v0.14.1 PS release HOT 2
- Enable value-level codecs to be used instead of type-level codecs HOT 3
- Is there a way to use `insert_` with `ON CONFLICT` HOT 3
- Add primitive queries that don't use type classes
- Update to the new `postgresql-client` API (upcoming v4.0.0)
- Mysql Support HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-selda.