如何在sqlalchemy中从PostgreSQL查询JSON数据类型的数据? [英] How to query data which is json datatype from postgresql in sqlalchemy?

查看:535
本文介绍了如何在sqlalchemy中从PostgreSQL查询JSON数据类型的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sqlalchemy中,我使用经典映射和autoload = True.我想从postgresql查询jsontype的数据.

In sqlalchemy, I use classical mapping and autoload=True. I want to query data which is jsontype from postgresql.

    D:\Python27\lib\site-packages\sqlalchemy\dialects\postgresql\base.py:1706: SAWarning:  Did not recognize type 'json' of column 'comm_media_alias'name, format_type, default, notnull, domains, enums, schema)

如何处理这个问题

推荐答案

PostgreSQL中的JSON类型是PostgreSQL中相对较新的数据类型,因此SQLAlchemy具有

The JSON type in PostgreSQL is a relatively new data type in PostgreSQL, and thus SQLAlchemy has only recently added functionality to properly detect it. At the time of this question, SQLAlchemy would not be able to detect the "JSON" column type, as doing so relied on functionality that it did not yet support.

SQLAlchemy 0.9已于2013年12月30日发布.此版本包含对PostgreSQL JSON数据类型的支持,因此,我建议升级到该版本并重试.

SQLAlchemy 0.9 was released on December 30th, 2013. This version contains support for the PostgreSQL JSON data type, so I would recommend upgrading to this version and trying again.

如果您无法升级(或者升级仍然无法进行),您还可以将列类型更改为其他类型(例如TEXT).

If you can't upgrade (or the upgrade still isn't working for you), you can also change your column type to something else (like TEXT).

关于此的另一件事要注意,它不是错误:它是警告.我不确定SQLAlchemy在处理JSON类型的列时将实际尝试做什么,但是无论如何它最终可能都会起作用.

Another thing to note about this is that it is not an error: it is a warning. I'm not sure what SQLAlchemy will actually try to do when it is working with the column that is a JSON type, but it might end up working anyway.

这篇关于如何在sqlalchemy中从PostgreSQL查询JSON数据类型的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆