summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/functions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-12-19 15:15:35 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-12-20 10:56:21 -0500
commit567878e5c67d08c561dd064fe6dc25e4db7349e7 (patch)
treedd0e50cbf7105758c0ea5931606c15f6e079c0b6 /lib/sqlalchemy/sql/functions.py
parent946058ec6070ab4db9fdfab612ec4543fea9cd1c (diff)
downloadsqlalchemy-567878e5c67d08c561dd064fe6dc25e4db7349e7.tar.gz
add joins_implicitly to column_valued()
Added parameter :paramref:`.FunctionElement.column_valued.joins_implicitly`, which is useful in preventing the "cartesian product" warning when making use of table-valued or column-valued functions. This parameter was already introduced for :meth:`.FunctionElement.table_valued` in :ticket:`7845`, however it failed to be added for :meth:`.FunctionElement.column_valued` as well. Fixes: #9009 Change-Id: Ifb72fbcb4f4d2998e730d6f85ec7280df3bf3d47
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
-rw-r--r--lib/sqlalchemy/sql/functions.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index 5ed89bc82..742f211c9 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -292,7 +292,7 @@ class FunctionElement(Executable, ColumnElement[_T], FromClause, Generative):
return new_func.alias(name=name, joins_implicitly=joins_implicitly)
- def column_valued(self, name=None):
+ def column_valued(self, name=None, joins_implicitly=False):
"""Return this :class:`_functions.FunctionElement` as a column expression that
selects from itself as a FROM clause.
@@ -308,6 +308,16 @@ class FunctionElement(Executable, ColumnElement[_T], FromClause, Generative):
gs = func.generate_series(1, 5, -1).alias().column
+ :param name: optional name to assign to the alias name that's generated.
+ If omitted, a unique anonymizing name is used.
+
+ :param joins_implicitly: when True, the "table" portion of the column
+ valued function may be a member of the FROM clause without any
+ explicit JOIN to other tables in the SQL query, and no "cartesian
+ product" warning will be generated. May be useful for SQL functions
+ such as ``func.json_array_elements()``.
+
+ .. versionadded:: 1.4.46
.. seealso::
@@ -319,7 +329,7 @@ class FunctionElement(Executable, ColumnElement[_T], FromClause, Generative):
""" # noqa: 501
- return self.alias(name=name).column
+ return self.alias(name=name, joins_implicitly=joins_implicitly).column
@util.ro_non_memoized_property
def columns(self):