You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
make sure also you specify return type as JSON for the above as it defaults to ARRAY which MariaDB does not seem to have:
func.array_agg(column, type_=JSON)
feel free to indicate which specific patterns you are seeking and I can illustrate how to do them and/or locate specific language features which need support. "add all JSON functions" is too general. thanks.
just noticed you changed to sqlite all the sudden. json_array_length also renders correctly. Gets a different result, I don't know why that is, but the SQL you ask for is rendered:
SELECT resource.id AS resource_id, json_array_length(resource.data) AS json_array_length_1
FROM resource
WHERE CAST(JSON_QUOTE(JSON_EXTRACT(resource.data, ?)) AS VARCHAR) = ?
2020-02-27 10:35:41,533 INFO sqlalchemy.engine.base.Engine ('$."name"', '"Doe"')
2020-02-27 10:35:41,533 DEBUG sqlalchemy.engine.base.Engine Col ('resource_id', 'json_array_length_1')
2020-02-27 10:35:41,533 DEBUG sqlalchemy.engine.base.Engine Row (4, 0)
[(4, 0)]
The json_array_length(X) function returns the number of elements in the JSON array X, or 0 if X is some kind of JSON value other than an array.
that these functions all work dramatically differently on different backends is why SQLAlchemy can't provide any kind of abstraction layer as far as their features. SQLite does not appear to have a "count how many elements in a json mapping" function.
Activity
zzzeek commentedon Feb 16, 2020
hi there -
please use func.
eg. array_agg: https://docs.sqlalchemy.org/en/13/core/functions.html?highlight=array_agg#sqlalchemy.sql.functions.array_agg
make sure also you specify return type as JSON for the above as it defaults to ARRAY which MariaDB does not seem to have:
func.array_agg(column, type_=JSON)
feel free to indicate which specific patterns you are seeking and I can illustrate how to do them and/or locate specific language features which need support. "add all JSON functions" is too general. thanks.
honglei commentedon Feb 27, 2020
Thanks! I test under sqlite3 3.31.1
zzzeek commentedon Feb 27, 2020
OK, there is no "json_array_length" function on MariaDB that I can find, did you mean "json_length" ? https://mariadb.com/kb/en/json_length/
your test script works if I use that:
SQL output:
zzzeek commentedon Feb 27, 2020
just noticed you changed to sqlite all the sudden. json_array_length also renders correctly. Gets a different result, I don't know why that is, but the SQL you ask for is rendered:
zzzeek commentedon Feb 27, 2020
this is not an ARRAY, it's a mapping:
https://www.sqlite.org/json1.html#jarraylen
The json_array_length(X) function returns the number of elements in the JSON array X, or 0 if X is some kind of JSON value other than an array.
that these functions all work dramatically differently on different backends is why SQLAlchemy can't provide any kind of abstraction layer as far as their features. SQLite does not appear to have a "count how many elements in a json mapping" function.
zzzeek commentedon Mar 3, 2020
no bug illustrated here for now.