django-pg-returning
A small library implementing PostgreSQL ability to return rows in DML statements for Django
Decision gist · record as of 2026-08-14
Yes, if you use PostgreSQL and Django and frequently need to return modified rows from bulk operations or F() expressions. The library is stable and has no known vulnerabilities, but its dormant maintenance (last release 2024-01-04, no recent commits) means it may not support the latest Django versions—verify compatibility with your Django version before adopting. Low install friction and permissive licensing make it a low-risk experiment.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires PostgreSQL 9.4+, psycopg2 or psycopg2-binary (not installed by this package), and Django 1.8+.
- Some features require Django 1.10+.
- Low friction: pure Python wheel with only django and typing as runtime dependencies.
License · maintenance · safety
permissive license (permissive) — BSD 3-clause permissive license; you may use, modify, and distribute freely with attribution and no warranty.
last release 2024-01-04 (953 days) · last repo commit 2024-09-19 · 18 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 178,490 downloads/mo, #10,192 on PyPI
Alternatives
Verify before relying
pip install django-pg-returning
from django_pg_returning import UpdateReturningModel
from django.db import models
class MyModel(UpdateReturningModel):
field = models.IntegerField()
result = MyModel.objects.all().update_returning(field=1)
print(result.count())- Whether the library works with current Django versions (4.x, 5.x) given dormant maintenance status.
- Compatibility with modern psycopg versions (3.x) and whether psycopg2 is still the expected adapter.
- Performance characteristics when returning large result sets or with complex F() expressions.
What it is and what it does
django-pg-returning bridges a gap in Django's ORM: it exposes PostgreSQL's RETURNING clause for UPDATE, DELETE, and bulk CREATE operations. Normally, Django's update() and delete() methods don't return the modified rows, and bulk_create() doesn't refresh fields with database-computed defaults or trigger-set values. This library adds QuerySet methods (update_returning, delete_returning, create_returning, bulk_create_returning) and model methods (save_returning) that execute the DML statement and immediately fetch back the affected rows, including any values computed by the database.
The result is a ReturningQuerySet—a cached, in-memory collection similar to Django's RawQuerySet but with convenience methods like count(), first(), last(), values(), and values_list(). This is especially useful when you rely on database defaults, triggers, or F() expressions to compute field values and need to know what was actually stored without issuing a separate SELECT.
Use it for
- Retrieve auto-generated or trigger-computed values after bulk inserts without a follow-up query.
- Update records with F() expressions and immediately see the evaluated result without reloading the instance.
- Delete rows and capture their final state (e.g., for audit logging) in a single round-trip.
- Bulk operations that depend on database defaults or computed columns to populate fields.
- Workflows where you need to confirm what the database actually stored after a DML operation.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you use PostgreSQL and Django and frequently need to return modified rows from bulk operations or F() expressions.
The library is stable and has no known vulnerabilities, but its dormant maintenance (last release 2024-01-04, no recent commits) means it may not support the latest Django versions—verify compatibility with your Django version before adopting. Low install friction and permissive licensing make it a low-risk experiment.
Install
django-pg-returning on PyPI
Before you install
Low friction: pure Python wheel with only django and typing as runtime dependencies. Maintenance is dormant—last release 2024-01-04, no commits since 2024-09-19—so expect no active support or updates for new Django versions.
Requires PostgreSQL 9.4+, psycopg2 or psycopg2-binary (not installed by this package), and Django 1.8+. Some features require Django 1.10+.
License in practice
BSD 3-clause permissive license; you may use, modify, and distribute freely with attribution and no warranty.
Quickstart
pip install django-pg-returning
from django_pg_returning import UpdateReturningModel
from django.db import models
class MyModel(UpdateReturningModel):
field = models.IntegerField()
result = MyModel.objects.all().update_returning(field=1)
print(result.count())
Verify before relying
- Whether the library works with current Django versions (4.x, 5.x) given dormant maintenance status.
- Compatibility with modern psycopg versions (3.x) and whether psycopg2 is still the expected adapter.
- Performance characteristics when returning large result sets or with complex F() expressions.
Package facts
| License | permissive license permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesdjangotyping |
| Maintenance | Dormant 953 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 178,490 / month, #10,192 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
Evidence: django_pg_returning-2.0.2-py2.py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “django postgresql returning clause”
- django-pg-returningExtends Django's ORM to capture and return rows modified by…
- buildpgbuildpg constructs PostgreSQL prepared statements with named…
- django-cteAdds Common Table Expressions (CTE) support to Django's ORM, enabling…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also django-pg-bulk-update · django-sql-utils · djangoql · django-bulk-update · django-postgres-copy · drf-extra-fields · django-soft-delete · modelsearch · django-chunkator · django-mock-queries