One more doubt is, is there a way to filter on the full json
something like this:
in your example only:
print(Session.query(Student).filter(Student.data_test
=={'foo':'bar'}).first())
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post
*VERSION* it was, was working with pg9.2, upgraded to pg9.6 and everything
works fine now.
Thank you so much.
--
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
What is the version of your PostgreSQL?
Here is an example. Works perfectly for me (pg9.6 and pg10).
https://gist.github.com/aCLr/7d794eabbf972a60a15f40b2d3965508
чт, 7 дек. 2017 г. в 16:05, :
> Hi,
>
> I tried using direct plain JSON:
>
> my model
> class
Hi,
I tried using direct plain JSON:
my model
class Student(db.Model):
__tablename__= 'students'
id=db.Column(db.Integer, primary_key=True,autoincrement=True)
name=db.Column(db.String(200))
roll_no=db.Column(db.Integer)
data_test=db.Column(db.JSON)
I tried this:
*a =
you can call "->>" (and any other) operator directly:
Student.data_test.op('->>')('foo') == 'bar'
if you want to call cast use this:
cast(Student.data_test['foo'], String) == 'bar'
"c" (the shortcut for "columns") allows for "Table" instances. If you use
declarative style, you can not to use it
Hi Mike,
as you said I tried this:
*from sqlalchemy.dialects import postgresql class Student(db.Model): #
...data_test=db.Column(postgresql.JSON) *
and I tried querying like this:
*a = Student.query.filter(Student.data_test["foo"].astext =="bar").first()*
tried this as well:
*a =