SQLAlchemy Postgres无法编译JSONB插入指令

时间:2018-06-13 18:47:32

标签: python json postgresql sqlalchemy jsonb

我试图获取用于插入JSONB的sql语句,但我得到了Not Implemented Error。我使用sqlalchemy 1.2.8和python 3.6.4。以下是我使用的代码:

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import JSONB

tbl = sa.table('test',
                sa.Column('a', sa.types.Integer, primary_key=True),
                sa.Column('b', sa.types.Text, primary_key=True),
                sa.Column('j', JSONB))
a=1
b="bar"
j = {"a1":"foo1", "b1":"bar1"}
str(tbl.insert().values(a=a, b=b, j=j).compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}))

我收到错误:

/usr/local/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py in render_literal_value(self, value, type_)
   1293         else:
   1294             raise NotImplementedError(
-> 1295                 "Don't know how to literal-quote value %r" % value)
   1296 
   1297     def _truncate_bindparam(self, bindparam):

NotImplementedError: Don't know how to literal-quote value {'a1': 'foo1', 'b1': 'bar1'}

非常感谢任何帮助!

0 个答案:

没有答案