Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "returning id" using asyncpg(pgsql)

Use asyncpg to execute the insert statement in Python, and use the returning id syntax to get the ID of each insert, but return the "INSERT 0 1"

Python 3.5

asyncpg (Using Connection Pool)

enter image description here

like image 450
John Doe. Avatar asked Apr 14 '26 04:04

John Doe.


1 Answers

Connection.fetch() (and its variants) can be used to return the results of any data-returning statement, including INSERT ... RETURNING id or INSERT ... RETURNING * if you need all columns.

like image 89
Elvis Pranskevichus Avatar answered Apr 15 '26 18:04

Elvis Pranskevichus