#27090: pg_get_serial_sequence is broken on postgres, use a lookup in
information_schema.columns instead
-------------------------------------+-------------------------------------
     Reporter:  Hanne Moa            |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  1.10
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  postgres sequence    |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Hanne Moa):

 The postgres-general list has some very interesting spam filters, took a
 while to get through. (Don't have a line in the body of the email starting
 with the word "which"...)

 https://www.postgresql.org/message-id/nu7ebq%24a2h%241%40blaine.gmane.org

 A different query is suggested, the result need not be parsed:

 "Personally, I'd try looking in pg_depend to see if the column's default
 expression has a dependency on a relation of type sequence.  That avoids
 all the fun of parsing the expression and turns it into a simple SQL
 join problem." -- Tom Lane

 It's a very simple join =):

 {{{
     select sn.nspname as sequence_schema, s.relname as sequence_name,
 col.attname
     from pg_class s
       join pg_namespace sn on sn.oid = s.relnamespace
       join pg_depend d on d.refobjid = s.oid and
 d.refclassid='pg_class'::regclass
       join pg_attrdef ad on ad.oid = d.objid and d.classid =
 'pg_attrdef'::regclass
       join pg_attribute col on col.attrelid = ad.adrelid and col.attnum =
 ad.adnum
       join pg_class tbl on tbl.oid = ad.adrelid
       join pg_namespace n on n.oid = tbl.relnamespace
     where s.relkind = 'S'
       and d.deptype in ('a', 'n')
       and n.nspname = 'public'
       and tbl.relname = 'THE_TABLE_NAME'
       and col.attname = 'THE_COLUMN_NAME'
 }}}

 Anyway, even using the information_schema, it might return a schema in
 addition to the name so adjustments need to be made to my existing code.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.ecf9be32e04e664302590ccd5a9d6802%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to