Yields ForeignKey named tuples
(self)
| 662 | return result[0] if result else "" |
| 663 | |
| 664 | def foreignkeys(self): |
| 665 | """Yields ForeignKey named tuples""" |
| 666 | |
| 667 | if self.conn.info.server_version < 90000: |
| 668 | return |
| 669 | |
| 670 | with self.conn.cursor() as cur: |
| 671 | query = """ |
| 672 | SELECT s_p.nspname AS parentschema, |
| 673 | t_p.relname AS parenttable, |
| 674 | unnest(( |
| 675 | select |
| 676 | array_agg(attname ORDER BY i) |
| 677 | from |
| 678 | (select unnest(confkey) as attnum, generate_subscripts(confkey, 1) as i) x |
| 679 | JOIN pg_catalog.pg_attribute c USING(attnum) |
| 680 | WHERE c.attrelid = fk.confrelid |
| 681 | )) AS parentcolumn, |
| 682 | s_c.nspname AS childschema, |
| 683 | t_c.relname AS childtable, |
| 684 | unnest(( |
| 685 | select |
| 686 | array_agg(attname ORDER BY i) |
| 687 | from |
| 688 | (select unnest(conkey) as attnum, generate_subscripts(conkey, 1) as i) x |
| 689 | JOIN pg_catalog.pg_attribute c USING(attnum) |
| 690 | WHERE c.attrelid = fk.conrelid |
| 691 | )) AS childcolumn |
| 692 | FROM pg_catalog.pg_constraint fk |
| 693 | JOIN pg_catalog.pg_class t_p ON t_p.oid = fk.confrelid |
| 694 | JOIN pg_catalog.pg_namespace s_p ON s_p.oid = t_p.relnamespace |
| 695 | JOIN pg_catalog.pg_class t_c ON t_c.oid = fk.conrelid |
| 696 | JOIN pg_catalog.pg_namespace s_c ON s_c.oid = t_c.relnamespace |
| 697 | WHERE fk.contype = 'f'; |
| 698 | """ |
| 699 | _logger.debug("Functions Query. sql: %r", query) |
| 700 | cur.execute(query) |
| 701 | for row in cur: |
| 702 | yield ForeignKey(*row) |
| 703 | |
| 704 | def functions(self): |
| 705 | """Yields FunctionMetadata named tuples""" |