Psycopg 3.2 released – PostgreSQL driver for Python
Psycopg 3.2 release brings Numpy scalar and PostgreSQL parameter format support, async enhancements, and PgBouncer interaction. It emphasizes maintaining crucial Python-PostgreSQL communication, aiding businesses and infrastructures with reliable interaction.
Read original articlePsycopg 3.2 has been released after almost two years of development, bringing new features like support for Numpy scalars, PostgreSQL parameter formats, and a scalar row factory for easier data retrieval. Additionally, it now supports new features from libpq 17, enhancing asynchronous operations, stream results, and PgBouncer interaction. The release also includes improvements in handling notifications and reducing code duplication through async-to-sync conversion tools. Maintaining Psycopg is highlighted as crucial for Python and PostgreSQL users, encouraging sponsorship for ongoing development. The update aims to enhance the communication between Python and PostgreSQL, catering to various businesses and critical infrastructures. Psycopg 3 continues to be a vital tool for ensuring reliable and efficient interaction between the two technologies.
Related
Schema changes and the Postgres lock queue
Schema changes in Postgres can cause downtime due to locking issues. Tools like pgroll help manage migrations by handling lock acquisition failures, preventing application unavailability. Setting lock_timeout on DDL statements is crucial for smooth schema changes.
GeoPandas 1.0.0
GeoPandas 1.0.0 simplifies geospatial data manipulation in Python by extending pandas with spatial operations using shapely. It eliminates the need for a spatial database, encouraging contributions and providing support.
Using short lived Postgres servers for testing
Database servers like PostgreSQL can be quickly set up for short-lived environments or CI/CD pipelines by creating new data directories and using pg_basebackup for efficient data population. This method simplifies testing and demo setups.
Our great database migration
Shepherd, an insurance pricing company, migrated from SQLite to Postgres to boost performance and scalability for their pricing engine, "Alchemist." The process involved code changes, adopting Neon database, and optimizing performance post-migration.
Relational Algebra Primer
Relational algebra underpins databases like PostgreSQL and MySQL. Bmg, a Ruby tool, bridges relational algebra and SQL databases, aiding data manipulation. Understanding relational algebra enriches SQL database skills and Bmg utilization.
from psycopg import connect, RawCursor
with connect(dsn, cursor_factory=RawCursor) as conn:
with conn.cursor() as cur:
cur.execute("SELECT $1, $2", [1, "Hello"])
assert cur.fetchone() == (1, "Hello")
The release notes highlight several interesting advantages I hadn't considered. However, they don't mention the primary motivation behind my contribution, so I thought I'd share it here:I was concerned that psycopg replaces the %s placeholders using regexes, which might inadvertently alter my SQL queries. My goal was to ensure that my SQL queries were passed directly to PostgreSQL "as is," without any intermediate modifications. Only PostgreSQL's parser can safely and accurately parse all SQL queries. While this concern might seem theoretical if you're certain your queries don't contain any %s, it still felt much more reassuring to eliminate this potential source of bugs entirely.
[1] https://www.psycopg.org/psycopg3/docs/advanced/cursors.html#...
Even though the latter was already safe, it simply looked toe-curling (like you were writing naive SQL-injectable queries all the time).
Performance charts speak for themselves. This lib uses the binary protocol while most are using text based comms.
Related
Schema changes and the Postgres lock queue
Schema changes in Postgres can cause downtime due to locking issues. Tools like pgroll help manage migrations by handling lock acquisition failures, preventing application unavailability. Setting lock_timeout on DDL statements is crucial for smooth schema changes.
GeoPandas 1.0.0
GeoPandas 1.0.0 simplifies geospatial data manipulation in Python by extending pandas with spatial operations using shapely. It eliminates the need for a spatial database, encouraging contributions and providing support.
Using short lived Postgres servers for testing
Database servers like PostgreSQL can be quickly set up for short-lived environments or CI/CD pipelines by creating new data directories and using pg_basebackup for efficient data population. This method simplifies testing and demo setups.
Our great database migration
Shepherd, an insurance pricing company, migrated from SQLite to Postgres to boost performance and scalability for their pricing engine, "Alchemist." The process involved code changes, adopting Neon database, and optimizing performance post-migration.
Relational Algebra Primer
Relational algebra underpins databases like PostgreSQL and MySQL. Bmg, a Ruby tool, bridges relational algebra and SQL databases, aiding data manipulation. Understanding relational algebra enriches SQL database skills and Bmg utilization.