goruneta
(goruneta)
1
Is there a way to use GROUP_CONCAT()
function in the SELECT
statement? Was looking for something like
from sql import Table
t = Table("t")
t.select(functions.GroupConcat(t.column, distinct=True))
but can’t seem to find a single function that alludes to performing a GROUP_CONCAT()
.
ced
(Cédric Krier)
2
GROUP_CONCAT is not a SQL standard function (it seems to exist only on MySQL).
But you can create your own version of aggregate expression like:
from sql.aggregate import Aggregate
class GroupConcat(Aggregate):
__slots__ = ()
_sql = 'GROUP_CONCAT'
But of course this will work only on MySQL database.
goruneta
(goruneta)
3
Thank you for the quick response.
As for
it seems to exist only on MySQL
it does also exist in SQLite.
But you can create your own version of aggregate expression like:
I’m sorry if this is obvious but is there a documentation for this? I would also like to add DISTINCT
to it if possible.
ced
(Cédric Krier)
4
Hum. SQLite is not well-known to follow standard neither
The code is the documentation.
The distinct option is automatically inherited from Aggregate class like many others.
goruneta
(goruneta)
5
The code is the documentation.
The distinct option is automatically inherited from Aggregate class like many others.
I see. I’ll be sure to read the source code then, thank you.
system
(system)
Closed
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.