[Django] #27452: Add Postgres serial field to contrib.postgres

49 views
Skip to first unread message

Django

unread,
Nov 6, 2016, 6:30:07 AM11/6/16
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
--------------------------------------------+------------------------
Reporter: Johannes Hoppe | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
Since we have the beautiful `contrib.postgres` package now, we can add a
couple more Postgres specific fields, that are not supported by MySQL but
handy to all the Postgres fan boys.

That being said, I guess it's a good idea to start with a serial field. A
serial is a 4 byte integer with an implicit sequence. Ergo its and auto
increment field for none primary keys! Yeah!

**Usecase:** You could have a customer number, or invoice number in your
code. Usually it is a good idea to not use a natural primary key,
therefore reusing the pk as that number could be considered bad. Having a
separate field with a separate sequence solves this issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/27452>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 6, 2016, 6:55:51 AM11/6/16
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
----------------------------------+--------------------------------------

Reporter: Johannes Hoppe | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Description changed by Burhan Khalid:

Old description:

> Since we have the beautiful `contrib.postgres` package now, we can add a
> couple more Postgres specific fields, that are not supported by MySQL but
> handy to all the Postgres fan boys.
>
> That being said, I guess it's a good idea to start with a serial field. A
> serial is a 4 byte integer with an implicit sequence. Ergo its and auto
> increment field for none primary keys! Yeah!
>
> **Usecase:** You could have a customer number, or invoice number in your
> code. Usually it is a good idea to not use a natural primary key,
> therefore reusing the pk as that number could be considered bad. Having a
> separate field with a separate sequence solves this issue.

New description:

Since we have the beautiful `contrib.postgres` package now, we can add a
couple more Postgres specific fields, that are not supported by MySQL but
handy to all the Postgres fan boys.

That being said, I guess it's a good idea to start with `Serial`.

The PostgreSQL documentation: https://www.postgresql.org/docs/9.1/static
/datatype-numeric.html describes the field as follows:

The data types `serial` and `bigserial` are not true types, but merely a
notational convenience for creating unique identifier columns (similar to
the AUTO_INCREMENT property supported by some other databases).

**Use Cases:**

1. Anywhere an automatic incrementing value is required, but a primary key
is often (mis)used.
2. Providing additional (user controlled) auto-incrementing values.


The primary benefit is that is isolates the primary key for the sole use
of maintaining referential integrity.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:1>

Django

unread,
Nov 6, 2016, 12:13:07 PM11/6/16
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
----------------------------------+--------------------------------------

Reporter: Johannes Hoppe | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Johannes Hoppe):

I opened a PR with an implementation that I am already using somewhere. It
added a couple of tests and documentation too.
I guess this is a good starting point for a discussion.

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:2>

Django

unread,
Nov 6, 2016, 12:13:37 PM11/6/16
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Hoppe):

* owner: (none) => Johannes Hoppe
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:3>

Django

unread,
Nov 8, 2016, 7:14:07 PM11/8/16
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:4>

Django

unread,
Dec 22, 2018, 8:10:20 AM12/22/18
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Hoppe):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:5>

Django

unread,
Dec 22, 2018, 10:56:03 AM12/22/18
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:6>

Django

unread,
Sep 10, 2019, 8:17:28 PM9/10/19
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Hoppe):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:7>

Django

unread,
Sep 11, 2019, 6:13:35 AM9/11/19
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:8>

Django

unread,
Sep 11, 2019, 6:34:01 AM9/11/19
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* version: 1.10 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:9>

Django

unread,
Sep 12, 2019, 6:50:43 PM9/12/19
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Hoppe):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:10>

Django

unread,
Feb 5, 2020, 6:28:18 AM2/5/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:11>

Django

unread,
May 21, 2020, 2:15:15 PM5/21/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by InvalidInterrupt):

* cc: InvalidInterrupt (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:12>

Django

unread,
May 23, 2020, 11:44:55 AM5/23/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Johannes Hoppe):

I closed my PR for now, due to a lack of interest. Since Django does
support returning values since v3.0 everyone who needs such a field can
build it. Yet, I don't have the time get the feature into Django for now.

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:13>

Django

unread,
May 23, 2020, 2:27:43 PM5/23/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Johannes
| Hoppe
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by InvalidInterrupt):

Replying to [comment:13 Johannes Hoppe]:


> I closed my PR for now, due to a lack of interest. Since Django does
support returning values since v3.0 everyone who needs such a field can
build it. Yet, I don't have the time get the feature into Django for now.

Do you mind if I continue working on this using your branch? Handling
sequence resets after loading fixtures will require changes to the DB
backend.

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:14>

Django

unread,
May 23, 2020, 3:00:33 PM5/23/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
----------------------------------+------------------------------------

Reporter: Johannes Hoppe | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Claude Paroz):

* owner: Johannes Hoppe => (none)
* status: assigned => new


Comment:

Latest comment from Johannes is clearly an invitation to help :-)

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:15>

Django

unread,
May 29, 2020, 3:42:12 PM5/29/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner:
| InvalidInterrupt

Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by InvalidInterrupt):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


Comment:

[https://github.com/django/django/pull/12989 New PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:17>

Django

unread,
Sep 23, 2020, 5:16:16 AM9/23/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner:
| InvalidInterrupt
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:18>

Django

unread,
Oct 20, 2020, 11:57:37 PM10/20/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner:
| InvalidInterrupt
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by InvalidInterrupt):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


Comment:

[https://github.com/django/django/pull/13580 New PR for Default
Expression]

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:19>

Django

unread,
Nov 14, 2020, 12:22:00 PM11/14/20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:

| InvalidInterrupt
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Maron):

* needs_docs: 0 => 1


* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:21>

Django

unread,
Jul 23, 2022, 5:23:34 AM7/23/22
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
| InvalidInterrupt
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

Does this still make sense now that Django is using identity columns for
`*AutoField`s?

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:22>

Django

unread,
Nov 8, 2022, 11:23:58 AM11/8/22
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
| InvalidInterrupt
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

Claude, yes I think that the move to identity columns on Postgres made
this feature even more desirable (e.g. #34131).

--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:23>

Django

unread,
Feb 20, 2024, 11:53:09 PMFeb 20
to django-...@googlegroups.com
#27452: Add Postgres serial field to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
| InvalidInterrupt
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

FWIW [https://forum.djangoproject.com/t/django-4-2-is-a-2nd-autofield-
like-field-on-a-model-possible/28278/4 someone was able to implement] an
`IdentityField` which is kind of the equivalent of `GeneratedField` if it
supported `AS IDENTITY`. It's not the equivalent of `SerialField` though
but it demonstrates that all the pieces are there to implement it based on
`db_returning` and `pre_save` returning a `Default` expression.
--
Ticket URL: <https://code.djangoproject.com/ticket/27452#comment:24>
Reply all
Reply to author
Forward
0 new messages