type_coerce("some value", JSON) means the value will be run through
the JSON datatype's bind processor first thus converting it to '"some
value"'.
using pg8000 1.11.0 the test seems to pass:
$ py.test test/dialect/test_suite.py -k
test_crit_against_string_coerce_type -s --log-debug=sqlalchemy.engine
--dburi postgresql+pg8000://scott:tiger@localhost/test
here's the relevant output you can see '"some value"':
INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE data_table (
id SERIAL NOT NULL,
name VARCHAR(30) NOT NULL,
data JSON,
nulldata JSON,
PRIMARY KEY (id)
)
INFO:sqlalchemy.engine.base.Engine:()
INFO:sqlalchemy.engine.base.Engine:COMMIT
INFO:sqlalchemy.engine.base.Engine:INSERT INTO data_table (name, data)
VALUES (%s, %s)
INFO:sqlalchemy.engine.base.Engine:(('r1', '{"key1": "value1", "key2":
"value2"}'), ('r2', '{"Key \'One\'": "value1", "key two": "value2",
"key three": "value \' three \'"}'), ('r3', '{"key1": [1, 2, 3],
"key2": ["one", "two", "three"], "key3": [{"four": "five"}, {"six":
"seven"}]}'), ('r4', '["one", "two", "three"]'), ('r5', '{"nested":
{"elem1": [{"a": "b", "c": "d"}, {"e": "f", "g": "h"}], "elem2":
{"elem3": {"elem4": "elem5"}}}}'), ('r6', '{"a": 5, "b": "some value",
"c": {"foo": "bar"}}'))
INFO:sqlalchemy.engine.base.Engine:COMMIT
INFO:sqlalchemy.engine.base.Engine:SELECT
data_table.name
FROM data_table
WHERE
data_table.name = %s AND CAST((data_table.data -> %s) AS VARCHAR) = %s
INFO:sqlalchemy.engine.base.Engine:('r6', 'b', '"some value"')
DEBUG:sqlalchemy.engine.base.Engine:Col (b'name',)
DEBUG:sqlalchemy.engine.base.Engine:Row ('r6',)
PASSED
>
> Thanks,
>
> Tony.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
>
http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See
http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
sqlalchemy+...@googlegroups.com.
> To post to this group, send email to
sqlal...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/sqlalchemy.
> For more options, visit
https://groups.google.com/d/optout.