Find all columns in a set of scoped_tables :param scoped_tbls: list of (schema, table, alias) tuples :return: list of column names
(self, scoped_tbls: list[tuple[str | None, str, str | None]])
| 1744 | yield (suggestion, Fuzziness.PERFECT) |
| 1745 | |
| 1746 | def populate_scoped_cols(self, scoped_tbls: list[tuple[str | None, str, str | None]]) -> list[str]: |
| 1747 | """Find all columns in a set of scoped_tables |
| 1748 | :param scoped_tbls: list of (schema, table, alias) tuples |
| 1749 | :return: list of column names |
| 1750 | """ |
| 1751 | columns = [] |
| 1752 | meta = self.dbmetadata |
| 1753 | |
| 1754 | # if scoped tables is empty, this is just after a SELECT so we |
| 1755 | # show all columns for all tables in the schema. |
| 1756 | if len(scoped_tbls) == 0 and self.dbname: |
| 1757 | # ``dbname`` can point at a schema whose metadata has not been |
| 1758 | # loaded yet: a ``USE`` switch updates the live completer's |
| 1759 | # ``dbname`` immediately while the matching tables are still being |
| 1760 | # fetched on a background thread. Default to an empty mapping in |
| 1761 | # that window instead of raising ``KeyError``. Grab the per-schema |
| 1762 | # dict once so a concurrent refresh swapping it out cannot break |
| 1763 | # the iteration mid-loop. |
| 1764 | schema_tables = meta["tables"].get(self.dbname, {}) |
| 1765 | for table in schema_tables: |
| 1766 | columns.extend(schema_tables[table]) |
| 1767 | return columns or ['*'] |
| 1768 | |
| 1769 | # query includes tables, so use those to populate columns |
| 1770 | for tbl in scoped_tbls: |
| 1771 | # A fully qualified schema.relname reference or default_schema |
| 1772 | # DO NOT escape schema names. |
| 1773 | schema = tbl[0] or self.dbname |
| 1774 | relname = tbl[1] |
| 1775 | escaped_relname = self.escape_name(tbl[1]) |
| 1776 | |
| 1777 | # We don't know if schema.relname is a table or view. Since |
| 1778 | # tables and views cannot share the same name, we can check one |
| 1779 | # at a time |
| 1780 | try: |
| 1781 | columns.extend(meta["tables"][schema][relname]) |
| 1782 | |
| 1783 | # Table exists, so don't bother checking for a view |
| 1784 | continue |
| 1785 | except KeyError: |
| 1786 | try: |
| 1787 | columns.extend(meta["tables"][schema][escaped_relname]) |
| 1788 | # Table exists, so don't bother checking for a view |
| 1789 | continue |
| 1790 | except KeyError: |
| 1791 | pass |
| 1792 | |
| 1793 | try: |
| 1794 | columns.extend(meta["views"][schema][relname]) |
| 1795 | except KeyError: |
| 1796 | pass |
| 1797 | |
| 1798 | return columns |
| 1799 | |
| 1800 | def populate_enum_values( |
| 1801 | self, |