Description
- asyncpg version:0.15.0
- PostgreSQL version: PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: No - Python version: 3.6
- Platform: window
- Do you use pgbouncer?: no
- Did you install asyncpg with pip?: yes
- If you built asyncpg locally, which version of Cython did you use?:
- Can the issue be reproduced under both asyncio and
uvloop?:
I'm using executemany to do bulk insert/upsert. The args passed in contains some datetime.datetime and datetime.date data. It seemed to fail to encode the datetime data.
The problem is it works fine if i use the function copy_records_to_table by passing in the same data.
Below is the stack and entry point of the call
await self.async_conn.executemany("insert into {}.{} ({}) values ({}) on conflict ({}) do update set {}"
.format(schema, table,
','.join(columns),
','.join(['$' + str(i) for i in range(1, len(columns) + 1)]),
','.join(keys),
','.join(["{} = EXCLUDED.{}".format(c, c) for c in columns])),
arglist)
File "C:\Users\chechen\AppData\Local\Continuum\anaconda3\lib\site-packages\asyncpg\connection.py", line 265, in executemany
return await self._executemany(command, args, timeout)
File "C:\Users\chechen\AppData\Local\Continuum\anaconda3\lib\site-packages\asyncpg\connection.py", line 1318, in _executemany
result, _ = await self._do_execute(query, executor, timeout)
File "C:\Users\chechen\AppData\Local\Continuum\anaconda3\lib\site-packages\asyncpg\connection.py", line 1333, in _do_execute
result = await executor(stmt, None)
File "asyncpg\protocol\protocol.pyx", line 238, in bind_execute_many
File "asyncpg\protocol\coreproto.pyx", line 814, in asyncpg.protocol.protocol.CoreProtocol._bind_execute_many
File "asyncpg\protocol\protocol.pyx", line 220, in genexpr
File "asyncpg\protocol\prepared_stmt.pyx", line 148, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
File "asyncpg\protocol\codecs/base.pyx", line 164, in asyncpg.protocol.protocol.Codec.encode
File "asyncpg\protocol\codecs/base.pyx", line 100, in asyncpg.protocol.protocol.Codec.encode_scalar
File "asyncpg\protocol\codecs/datetime.pyx", line 138, in asyncpg.protocol.protocol.timestamp_encode
TypeError: unsupported operand type(s) for -: 'datetime.date' and 'datetime.datetime'