On Dec 23, 2:55 pm, Christophe Pettus <x...@thebuild.com> wrote:
> On Dec 23, 2010, at 11:35 AM, Eric wrote:
>
> > a) To fix this, one must identify the sequences that are not correct.
> > I scoured pg_catalog and friends and cannot identify where PostgreSQL
> > exposes the link between the "id" and sequence columns.
>
> Just FYI, it's stored in pg_depend.

Thanks for the tip. If anyone else hits this, the following adapted
from another pg recipe will output all correct id <-> serial
ownerships.

SELECT s1.nspname || '.' || t1.relname AS tablename,
a.attname,
s2.nspname || '.' || t2.relname AS sequencename
FROM pg_depend AS d
JOIN pg_class AS t1 ON t1.oid = d.refobjid
JOIN pg_class AS t2 ON t2.oid = d.objid
JOIN pg_namespace AS s1 ON s1.oid = t1.relnamespace
JOIN pg_namespace AS s2 ON s2.oid = t2.relnamespace
JOIN pg_attribute AS a ON a.attrelid = d.refobjid AND a.attnum =
d.refobjsubid
WHERE t1.relkind = 'r'
AND t2.relkind = 'S'
ORDER BY tablename, a.attname, sequencename;

Comparing the output of a production database vs. what Django would
create natively on an empty DB will spit out the exact columns that
are missing the OWNED BY link. I'm sure there's a more elegant way,
but this was quick and easy.

Thanks Christophe!

>
> --
> -- Christophe Pettus
>    x...@thebuild.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to