def populate_scoped_cols(self, scoped_tbls):
        """ Find all columns in a set of scoped_tables
        :param scoped_tbls: list of TableReference namedtuples
        :return: list of column names
        """

        columns = []
        meta = self.dbmetadata

        for tbl in scoped_tbls:
            if tbl.schema:
                # A fully qualified schema.relname reference
                schema = self.escape_name(tbl.schema)
                relname = self.escape_name(tbl.name)

                if tbl.is_function:
                    # Return column names from a set-returning function
                    try:
                        # Get an array of FunctionMetadata objects
                        functions = meta['functions'][schema][relname]
                    except KeyError:
                        # No such function name
                        continue

                    for func in functions:
                        # func is a FunctionMetadata object
                        columns.extend(func.fieldnames())
                else:
                    # We don't know if schema.relname is a table or view. Since
                    # tables and views cannot share the same name, we can check
                    # one at a time
                    try:
                        columns.extend(meta['tables'][schema][relname])

                        # Table exists, so don't bother checking for a view
                        continue
                    except __HOLE__:
                        pass

                    try:
                        columns.extend(meta['views'][schema][relname])
                    except KeyError:
                        pass

            else:
                # Schema not specified, so traverse the search path looking for
                # a table or view that matches. Note that in order to get proper
                # shadowing behavior, we need to check both views and tables for
                # each schema before checking the next schema
                for schema in self.search_path:
                    relname = self.escape_name(tbl.name)

                    if tbl.is_function:
                        try:
                            functions = meta['functions'][schema][relname]
                        except KeyError:
                            continue

                        for func in functions:
                            # func is a FunctionMetadata object
                            columns.extend(func.fieldnames())
                    else:
                        try:
                            columns.extend(meta['tables'][schema][relname])
                            break
                        except KeyError:
                            pass

                        try:
                            columns.extend(meta['views'][schema][relname])
                            break
                        except KeyError:
                            pass

        return columns
dataset/ETHPy150Open dbcli/pgcli/pgcli/pgcompleter.py/PGCompleter.populate_scoped_cols