sqlalchemy.exc.UnsupportedCompilationError JSONB

Issue #3549 invalid
flashmob
created an issue

Trying to compile query:

_update = str(S.__table__.update().where(and_(*_filters)).values({col.name: func.jsonb_concat(col,func.cast(bindparam(bind_name), JSONB))}))

and getting error:

sqlalchemy.exc.UnsupportedCompilationError: Compiler <sqlalchemy.sql.compiler.GenericTypeCompiler object at 0x108cd6110> can't render element of type <class 'sqlalchemy.dialects.postgresql.json.JSONB'>

if I remove cast then sqlalchemy trying to cast dict to HSTORE

Comments (17)

  1. flashmob reporter

    btw, str(stmt.compile(dialect=postgresql.dialect())) returns different string, I always was getting params like ":b_state" now they all compiled and I see "%(b_state)s"

  2. flashmob reporter

    Long story...I use statement where i can, but I'm using partitioning in PG and for update queries I'm generating string where I change table name

    _update = str(S.__table__.update().where(and_(*_filters)).values(_values)).replace(S.__tablename__, '%(tablename)s'))
    

    then I do:

    execute(text(_update % {'tablename': tablename}), params)
    

    couldn't made up a better solution.

  3. flashmob reporter

    can't make statement with returning

    S.__table__.update().where(and_(*_filters)).values(_values).returning(S.id)
    

    where should I put dialect name? Really can't find anything in docs :(

  4. flashmob reporter

    I'm sorry, my mistake, copypasted code without buildng str from statement but was actually building it in my code. Sorry for stupid questions :)

  5. Log in to comment