MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / column_valued

Method column_valued

lib/sqlalchemy/sql/functions.py:344–385  ·  view source on GitHub ↗

Return this :class:`_functions.FunctionElement` as a column expression that selects from itself as a FROM clause. E.g.: .. sourcecode:: pycon+sql >>> from sqlalchemy import select, func >>> gs = func.generate_series(1, 5, -1).column_valued()

(
        self, name: Optional[str] = None, joins_implicitly: bool = False
    )

Source from the content-addressed store, hash-verified

342 return new_func.alias(name=name, joins_implicitly=joins_implicitly)
343
344 def column_valued(
345 self, name: Optional[str] = None, joins_implicitly: bool = False
346 ) -> TableValuedColumn[_T]:
347 """Return this :class:`_functions.FunctionElement` as a column expression that
348 selects from itself as a FROM clause.
349
350 E.g.:
351
352 .. sourcecode:: pycon+sql
353
354 >>> from sqlalchemy import select, func
355 >>> gs = func.generate_series(1, 5, -1).column_valued()
356 >>> print(select(gs))
357 {printsql}SELECT anon_1
358 FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3) AS anon_1
359
360 This is shorthand for::
361
362 gs = func.generate_series(1, 5, -1).alias().column
363
364 :param name: optional name to assign to the alias name that's generated.
365 If omitted, a unique anonymizing name is used.
366
367 :param joins_implicitly: when True, the "table" portion of the column
368 valued function may be a member of the FROM clause without any
369 explicit JOIN to other tables in the SQL query, and no "cartesian
370 product" warning will be generated. May be useful for SQL functions
371 such as ``func.json_array_elements()``.
372
373 .. versionadded:: 1.4.46
374
375 .. seealso::
376
377 :ref:`tutorial_functions_column_valued` - in the :ref:`unified_tutorial`
378
379 :ref:`postgresql_column_valued` - in the :ref:`postgresql_toplevel` documentation
380
381 :meth:`_functions.FunctionElement.table_valued`
382
383 """ # noqa: 501
384
385 return self.alias(name=name, joins_implicitly=joins_implicitly).column
386
387 @util.ro_non_memoized_property
388 def columns(self) -> ColumnCollection[str, KeyedColumnElement[Any]]: # type: ignore[override] # noqa: E501

Callers 11

CoreFixturesClass · 0.80
test_fn_valuedMethod · 0.80
pg_stuff.pyFile · 0.80
test_plain_old_unnestMethod · 0.80
test_column_valuedMethod · 0.80
test_scalar_stringsMethod · 0.80

Calls 1

aliasMethod · 0.95

Tested by 9

test_fn_valuedMethod · 0.64
test_plain_old_unnestMethod · 0.64
test_column_valuedMethod · 0.64
test_scalar_stringsMethod · 0.64