-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with parsing JSON/JSONB #138
Comments
This is a bit similar to #141 |
hey @LKay, what DB backend do you use? it might get down to the driver and dialect specifics, a test case would be also fantastic. |
I’m using asyncpg with postgres 11. |
For me, the issue appears to be related to making manual queries with a postgres URL
|
The problem is when you pass a string (or "raw query") into So it doesn't know what to cast the JSON column as when you call Whereas, when you pass a SQLAlchemy object, the |
Got the same issue with Mysql
|
up, has anyone tried to resolve it? Maybe we will see a fix in the near future? |
I'll take a look into it. |
I was having the same questions and looked for examples for quite some time. This seems like a decent approach: https://pgjones.dev/blog/quart-postgres-2021. I'm working on integrating this solution into a FastAPI project. It would be nice if this was easier to configure, I think a lot of people would benefit. Using json columns has become a default practice for me when developing APIs with evolving schemas or there's a need for configs or metadata to be stored alongside structure data records. |
I want to use some columns to store json data inside my postgres json or jsonb columns but when data is fetched the data is not being converted back to it's original basic
dict
type.Let's have a column with definition:
When I save a dictionary of structure a follow the data is stored correctly in the database using internal converter:
When reading the data back it comes back as array of strings that I have to deserialize back to dictionary:
I tried to create my custom type according to SQL Alchemy docs: https://docs.sqlalchemy.org/en/13/core/custom_types.html and came up with:
and redefined my column to:
This, however doesn't solve anything. The
result_processor
andprocess_result_value
are never called and I have to manually iterate through list and deserialize json string outside query.The text was updated successfully, but these errors were encountered: