I want to insert with Asyncpg some json data in a table (2 columns: id , cluster_json). I want to use the "executemany" function to speedup the insert process.
my code:
async def main():
conn = await asyncpg.connect('postgresql://postgres:postgres@localhost:5432/postgres')
statement = '''INSERT INTO cluster(cluster_json) VALUES($1) '''
await conn.executemany(statement, [{"name":"John", "age":30, "car":null},
{"name":"John1", "age":31, "car":null}'])
await conn.close()
asyncio.get_event_loop().run_until_complete(main())
but I get the following error :
asyncpg.exceptions.DataError: invalid input in executemany() argument sequence element #0: expected a sequence, got dict
I tryied to pass the dictionaries as str. also got a bug.
The error message is clear , the code the pretty similar to the one in the documentation,
expect that I want insert json data . Unfortunately, I don't see what I am missing.
Does someone spot the issue / help me ?
Thanks in advance.