3

I'm trying to get a sql statement for inserting JSONB but I get a Not Implemented Error. I am using sqlalchemy 1.2.8 and python 3.6.4. The following is the code I'm using:

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}))

I get error:

/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'}

Any assistance is greatly appreciated!

Skorpeo
  • 2,362
  • 2
  • 15
  • 20
  • it's not only because of JSONB, you will get the same results with JSON and other *fancy* types. What do you need exactly about this literal statement ? You may find some help in this [answer](https://stackoverflow.com/a/5698357/6655211) it provides a solution to outputs differents types, you just need to add JSON (in `LiteralDialect`). – PRMoureu Jun 13 '18 at 21:32
  • thanks, i was going to use sqlalchemy to create queries for another backend. – Skorpeo Jun 14 '18 at 12:11

0 Answers0