I was wondering what the major changes between psycopg2 and psycopg3 were. Found a post from the maintainer here: <a href="https://www.varrazzo.com/blog/2020/03/06/thinking-psycopg3/" rel="nofollow">https://www.varrazzo.com/blog/2020/03/06/thinking-psycopg3/</a><p>Main takeaways:<p>- Asyncio from the ground up<p>- Uses PQexecParams to do database-side escaping and interpolation<p>- ContextManager and transaction api improvements for<p>- Python only fallback if the C extension fails to build
Just a huge thank you to Daniele for developing and maintaining psycopg! The article shows the level of professionalism and care that goes into this project. Using Django to test implementation is a genius idea. I can't wait to try the new version in a few of my projects, the changes (especially server-side parameters binding) sound great.
A somebody who first started using DB code from Perl, and later learned Python, I always wondered by Python doesn't have a general database interface like DBI in Perl.<p>In Perl, all the database specific modules have a DBI backend, and all the higher-level modules (django-like frameworks, for example) rely on DBI.<p>In Python, SQLAlchemy has its own psycopg and cmysql integrations, and does django, and likely several other frameworks.<p>(Java has a similar standard, with JDBC, I believe; though I have never used it, so I might be misunderstanding something here).
Casually building a django db backend as an acceptance test. Nice work and great write up!<p>I had déjà vu reading the section on bind parameters in aggregate queries. The oracle backend had a similar issue that was fixed/hacked by comparing values and grouping them into named parameters. <a href="https://code.djangoproject.com/ticket/27632" rel="nofollow">https://code.djangoproject.com/ticket/27632</a>
The example syntax for connection handling is perfect. The footgun of not releasing the connection (especially from pools at the end of the with) is real. And the concepts are different (block of transactions vs normal with file xxx. )<p><pre><code> with connect(DSN) as conn:
with conn.transaction():
do_something()
with conn.transaction():
do_something_nested()
with conn.transaction() as tx:
do_something_else()
# we were just testing and we don't really want to do this
tx.rollback()
# and here the connection is closed
</code></pre>
Any chance of pushing some changes up into the postgresql side? I'm thinking of a block of trx with params separate? Didn't look at it at all.