Created
December 13, 2012 11:10
-
-
Save KangOl/4275791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_fk_on(cr, table, ignored): | |
q = """ SELECT cl1.relname as table, | |
att1.attname as column | |
FROM pg_constraint as con, pg_class as cl1, pg_class as cl2, | |
pg_attribute as att1, pg_attribute as att2 | |
WHERE con.conrelid = cl1.oid | |
AND con.confrelid = cl2.oid | |
AND array_lower(con.conkey, 1) = 1 | |
AND con.conkey[1] = att1.attnum | |
AND att1.attrelid = cl1.oid | |
AND cl2.relname = %s | |
AND att2.attname = 'id' | |
AND array_lower(con.confkey, 1) = 1 | |
AND con.confkey[1] = att2.attnum | |
AND att2.attrelid = cl2.oid | |
AND con.contype = 'f' | |
AND cl1.relname not in %s | |
""" | |
return cr.execute(q, (table, tuple(ignored))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment