PostgreSQL Tutorial

  • Home
  • Administration
  • Views
  • Triggers
  • Stored Procedures
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
Home / PostgreSQL Python

PostgreSQL Python

This PostgresQL Python section shows you how to work with PostgreSQL database using Python programming language.

Python has various database drivers for PostgreSQL. Currently, the psycopg is the most popular PostgreSQL database adapter for the Python language. The psycopg fully implements the Python DB-API 2.0 specification.

The current version of the psycopg is 2 or psycopg2. The psycopg2 database adapter implemented in C as a libpq wrapper resulting in both fast and secure. The psycopg2 provides many useful features such as client-side and server-side cursors, asynchronous notification and communication, COPY command support, etc.

In addition, the psycopg2 driver supports many Python types out-of-the-box. The psycopg2 matches Python objects to the PostgreSQL data types e.g., list to the array, tuples to records, and dictionary to hstore.  If you want to customize and extend the type adaption, you can use a flexible object adaption system.

This PostgreSQL Python section covers the most common activities for interacting with PostgreSQL in Python application:

  • Connecting to the PostgreSQL database server – shows you how to connect to the PostgreSQL database server from a Python application.
  • Creating new PostgreSQL tables in Python – provides you with the steps of creating new tables in PostgreSQL using psycopg2.
  • Inserting data into the PostgreSQL table in Python – explains to you how to insert data into a PostgreSQL database table in Python.
  • Updating data in the PostgreSQL table in Python – learns various ways to update data in the PostgreSQL table.
  • Querying data from the PostgreSQL tables – walks you through the steps of querying data from the PostgreSQL tables in a Python application.
  • Calling PostgreSQL stored procedure in Python – guides you how to call stored procedures from the PostgreSQL database in a Python application.
  • Handling PostgreSQL BLOB data in Python– gives you an example of inserting and selecting the PostgreSQL BLOB data in a Python application.
  • Deleting data in PostgreSQL table in Python – shows you how to delete data in a table in Python.

For the demonstration purpose, we will use the suppliers sample database. The following picture illustrates structure of the suppliers database:

PostgreSQL Python Sample Database Diagram

The suppliers database has the following tables:

  1.  vendors table: stores vendor data.
  2.  parts table: stores parts data.
  3.  parts_drawings table: stores the drawing of a part.
  4.  vendor_parts table: stores the data of which parts supplied by which vendor.
Previous Tutorial: PostgreSQL PHP
Next Tutorial: PostgreSQL JDBC

PostgreSQL Quick Start

  • What is PostgreSQL?
  • Install PostgreSQL
  • Connect to Database
  • Download PostgreSQL Sample Database
  • Load Sample Database
  • Explore Server and Database Objects

PostgreSQL Python

  • Connect To PostgreSQL Database
  • Create Tables in Python
  • Insert Data Into Table in Python
  • Update Data in Python
  • Query Data in Python
  • Handle Transactions in Python
  • Call PostgreSQL Stored Procedures in Python
  • Working with BLOB Data in Python
  • Delete Data from Tables in Python

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • PostgreSQL Recursive View
  • Learn PostgreSQL Recursive Query By Example
  • Creating Updatable Views Using the WITH CHECK OPTION Clause
  • PostgreSQL Upsert Using INSERT ON CONFLICT statement
  • How to Generate a Random Number in A Range
  • Using PostgreSQL ADD COLUMN to Add One or More Columns To a Table
  • PostgreSQL Character Types: CHAR, VARCHAR, and TEXT
  • Using PostgreSQL SERIAL To Create Auto-increment Column
  • PostgreSQL Boolean Data Type with Practical Examples
  • Understanding PostgreSQL Timestamp Data Types

More Tutorials

  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Functions
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2016 by PostgreSQL Tutorial Website. All Rights Reserved.