Skip to content

Can't get Delete with executemany to work #183

@sumitvakil

Description

@sumitvakil
  • asyncpg version: 0.12.0
  • PostgreSQL version: 9.6.3, 64-bit
  • Python version: 3.6.1
  • Platform: Windows 10
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: Not applicable
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Haven't tried uvloop

Please see the following code, which is a modified copy of one of your samples. The insert with executemany works fine. However, the delete does not. The traceback of the error is as follows:

import asyncio
import asyncpg
import datetime

async def main():
    # Establish a connection to an existing database named "test"
    # as a "postgres" user.
    conn = await asyncpg.connect('postgresql://postgres@localhost/test')

    # Execute a statement to create a new table.
    await conn.execute('''
        CREATE TABLE users(
            id serial PRIMARY KEY,
            name varchar,
            addr varchar
        )
    ''')

    # Insert records into the created table.
    add_users = [
        ('bob', '1 Main St.'),
        ('joe', '800 Industrial Pkwy'),
        ('sam', '1234 Country Ln')
    ]

    await conn.executemany('''
        INSERT INTO users(name, addr) VALUES($1, $2)
    ''', add_users)

    # Delete two users
    del_users = [
        ('bob'), ('joe')
    ]

    # The following does not work
    await conn.executemany('''
        DELETE FROM users WHERE name = ($1)
    ''', del_users)

    # Close the connection.
    await conn.close()

asyncio.get_event_loop().run_until_complete(main())

Traceback (most recent call last):
File "c:\src\test\test2.py", line 43, in
asyncio.get_event_loop().run_until_complete(main())
File "c:\Anaconda3\lib\asyncio\base_events.py", line 466, in run_until_complete
return future.result()
File "c:\src\test\test2.py", line 38, in main
''', del_users)
File "c:\Anaconda3\lib\site-packages\asyncpg\connection.py", line 264, in executemany
return await self._executemany(command, args, timeout)
File "c:\Anaconda3\lib\site-packages\asyncpg\connection.py", line 1195, in _executemany
return await self._do_execute(query, executor, timeout)
File "c:\Anaconda3\lib\site-packages\asyncpg\connection.py", line 1209, in _do_execute
result = await executor(stmt, None)
File "asyncpg\protocol\protocol.pyx", line 221, in bind_execute_many (asyncpg/protocol/protocol.c:67401)
File "asyncpg\protocol\coreproto.pyx", line 814, in asyncpg.protocol.protocol.CoreProtocol._bind_execute_many (asyncpg/protocol/protocol.c:58921)
File "asyncpg\protocol\protocol.pyx", line 206, in genexpr (asyncpg/protocol/protocol.c:67031)
File "asyncpg\protocol\prepared_stmt.pyx", line 103, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg (asyncpg/protocol/protocol.c:62407)
ValueError: number of arguments (3) does not match number of parameters (1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions