diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-07-10 21:24:17 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-07-10 21:27:12 -0400 |
commit | 3916bfc9ccf2904f69498075849a82ceee225b3a (patch) | |
tree | ab835bf174a4047de0d2b62f6a3ac2731c321434 /lib/sqlalchemy/sql/elements.py | |
parent | 805a1323b973a30af99ce506dd5c5c4ab96cff0f (diff) | |
download | sqlalchemy-3916bfc9ccf2904f69498075849a82ceee225b3a.tar.gz |
support "SELECT *" for ORM queries
A :func:`_sql.select` construct that is passed a sole '*' argument for
``SELECT *``, either via string, :func:`_sql.text`, or
:func:`_sql.literal_column`, will be interpreted as a Core-level SQL
statement rather than as an ORM level statement. This is so that the ``*``,
when expanded to match any number of columns, will result in all columns
returned in the result. the ORM- level interpretation of
:func:`_sql.select` needs to know the names and types of all ORM columns up
front which can't be achieved when ``'*'`` is used.
If ``'*`` is used amongst other expressions simultaneously with an ORM
statement, an error is raised as this can't be interpreted correctly by the
ORM.
Fixes: #8235
Change-Id: Ic8e84491e14acdc8570704eadeaeaf6e16b1e870
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index eae06377f..9db90cb02 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -347,6 +347,7 @@ class ClauseElement( _is_lambda_element = False _is_singleton_constant = False _is_immutable = False + _is_star = False @property def _order_by_label_element(self) -> Optional[Label[Any]]: @@ -2174,6 +2175,10 @@ class TextClause( _allow_label_resolve = False + @property + def _is_star(self): + return self.text == "*" + def __init__(self, text: str): self._bindparams: Dict[str, BindParameter[Any]] = {} @@ -4535,6 +4540,10 @@ class ColumnClause( _is_multiparam_column = False + @property + def _is_star(self): + return self.is_literal and self.name == "*" + def __init__( self, text: str, |