psycopg
The most widely used Python driver for PostgreSQL databases.
In more detail
Code opens a connection, gets a cursor from it and runs queries with cursor.execute. Its cursor.execute takes SQL text and, separately, a tuple of parameters; passing values that way prevents SQL injection.
Example
conn = psycopg.connect("host=db dbname=postgres user=postgres password=secret")Related terms
- prepared statement — A SQL statement with placeholders, such as ?, whose values are sent separately from the SQL text instead of pasted into it.
- database — A program that stores data in an organised way and answers questions about it, such as PostgreSQL.
- PostgreSQL — A widely used open source relational database server with strict typing, rich data types and extensions.
- transaction — A group of database changes that succeed or fail together, so the data is never left half-updated.
- autocommit — A database connection mode in which every statement is committed immediately as its own transaction.
Taught in
- Static Application Security Testing with Semgrep — Cloud Security & DevSecOps Engineering
- Dual Writes And Why They Lose Data — Apache Kafka & Event Streaming
- The Transactional Outbox — Apache Kafka & Event Streaming