MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

Inserting multiple values in a row #1106

Open RomulBY opened 10 months ago

RomulBY commented 10 months ago

Hello. I'm migrating from psycopg2 to asyncpg and I still don't understand much and have questions. Sorry if they are stupid :)

To fill all the cells in a row in psycopg2 I specified:

"""INSERT INTO table_name VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);""",
                (
                    "here is a list of data"
                )

For the same operation in asyncpg I need to specify the names of all columns, i.e. the code is twice as large. Is this the only correct solution?

"""INSERT INTO table_name
                 (
                    "here is a list of column names"
                 )
                 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);""",
                (
                    "here is a list of data"
                )
elprans commented 10 months ago

You don't have to specify the names of the columns with asyncpg either. What makes you think you do?

RomulBY commented 10 months ago

You don't have to specify the names of the columns with asyncpg either. What makes you think you do?

I tried it, but it didn't work. Now I tried it again and it works. Perhaps I made some other mistake. I'm very sorry, sorry for taking up your time.