1

I'm using execute_values to insert the content of many tables on other tables, I already set the adapter of dict to json when I received other error, however I don't know how to treat this one:

psycopg2.ProgrammingError: column "rules" is of type jsonb[] but expression is of type text[] LINE 1: ...UES (1,'tturxvrtgvvsrqgzsedcoyqujakyepjordrbbjdw',ARRAY['{"i...

The only way to handle that was something like this issue, but I would need to treat each column ...

Maybe there are ways to create a new adapter, but I couldn't achieve how to do that by the docs.

register_adapter(dict, Json)

execute_values(
            dest_cursor,
            f'''
            INSERT INTO {t} VALUES %s ON CONFLICT DO NOTHING;
            ''',
            records,
    )

Is there a automatic way to deal with that, like the register_adapter?

1 Answer 1

2

I've found the answer by this issue I learned I could use the template parameter, like so:

execute_values(
  dest_cursor,
  f'''
  INSERT INTO {t} VALUES %s ON CONFLICT DO NOTHING;
  ''',
  records,
  template="(%s, %s, %s::jsonb[], %s, %s)" # as many placeholders requested
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.