Opened 5 years ago

Last modified 2 years ago

#30511 closed New feature

AutoField with postgres10/11 as generated identity. — at Version 2

Reported by: Michael Kany Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: postgres generated identity
Cc: Michael Kany Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

We are currently working on a Django / Postgresql 11 project. We needed an adjustment for the postgres module because of its compatibility with .NET Framework and dataset generation.
In postgres 10/11 there is the new feature identity column called GENERATED AS IDENTITY instead of serial.
column_name type GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY [(sequence_option)]
We have created a module based on db.backends.postgres that adds 2 new django model fields. I would like implement the new feature into pyodbc module or new module for postgres 10/11 useful for later versions of django.

Adjustments only in base.py (line 70ff):

data_types = {
        'IdentityAutoField': 'integer',
        'IdentityBigAutoField': 'bigint',

and schema.py, def column_sql () (line 178ff):

# Primary key / unique outputs
        if field.primary_key:
            sql + = "PRIMARY KEY"
            if field.get_internal_type () in ("IdentityAutoField", "IdentityBigAutoField"):
                sql + = "GENERATED ALWAYS AS IDENTITY"
        elif field.unique:
            sql + = "UNIQUE"

I can also send our code

best regards
Michael Kany

Change History (4)

by Michael Kany, 5 years ago

Attachment: schema.py added

by Michael Kany, 5 years ago

Attachment: base.py added

comment:1 by Michael Kany, 5 years ago

Cc: Michael Kany added

the new Fields 'IdentityAutoField': 'integer', 'IdentityBigAutoField': 'bigint', the new fields could also be implemented as AutoFiled or BigAutoField, similar to the oracle module

comment:2 by Mariusz Felisiak, 5 years ago

Description: modified (diff)
Summary: AutoField with postgres10/11 as generated identityAutoField with postgres10/11 as generated identity.
Version: 2.2master

Thanks for the report. Can you provide more details about your use case? Can you also clarify what are you proposing? e.g.

  • using GENERATED AS IDENTITY instead of serial on PostgreSQL (I don't see much value in this),
  • adding extra fields to the PostgreSQL backends.

In Oracle we used GENERATED AS IDENTITY because there is no other way to create serial-like columns on Oracle which is not the case on PostgreSQL.

Note: See TracTickets for help on using tickets.
Back to Top