Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé
Classe « FunctionElement »

Méthode sqlalchemy.FunctionElement.table_valued

Signature de la méthode table_valued

def table_valued(self, *expr: '_ColumnExpressionOrStrLabelArgument[Any]', **kw: 'Any') -> 'TableValuedAlias' 

Description

help(FunctionElement.table_valued)

Return a :class:`_sql.TableValuedAlias` representation of this
:class:`_functions.FunctionElement` with table-valued expressions added.

e.g.:

.. sourcecode:: pycon+sql

    >>> fn = func.generate_series(1, 5).table_valued(
    ...     "value", "start", "stop", "step"
    ... )

    >>> print(select(fn))
    {printsql}SELECT anon_1.value, anon_1.start, anon_1.stop, anon_1.step
    FROM generate_series(:generate_series_1, :generate_series_2) AS anon_1{stop}

    >>> print(select(fn.c.value, fn.c.stop).where(fn.c.value > 2))
    {printsql}SELECT anon_1.value, anon_1.stop
    FROM generate_series(:generate_series_1, :generate_series_2) AS anon_1
    WHERE anon_1.value > :value_1{stop}

A WITH ORDINALITY expression may be generated by passing the keyword
argument "with_ordinality":

.. sourcecode:: pycon+sql

    >>> fn = func.generate_series(4, 1, -1).table_valued(
    ...     "gen", with_ordinality="ordinality"
    ... )
    >>> print(select(fn))
    {printsql}SELECT anon_1.gen, anon_1.ordinality
    FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3) WITH ORDINALITY AS anon_1

:param \*expr: A series of string column names that will be added to the
 ``.c`` collection of the resulting :class:`_sql.TableValuedAlias`
 construct as columns.  :func:`_sql.column` objects with or without
 datatypes may also be used.

:param name: optional name to assign to the alias name that's generated.
 If omitted, a unique anonymizing name is used.

:param with_ordinality: string name that when present results in the
 ``WITH ORDINALITY`` clause being added to the alias, and the given
 string name will be added as a column to the .c collection
 of the resulting :class:`_sql.TableValuedAlias`.

:param joins_implicitly: when True, the table valued function may be
 used in 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_each()``.

 .. versionadded:: 1.4.33

.. versionadded:: 1.4.0b2


.. seealso::

    :ref:`tutorial_functions_table_valued` - in the :ref:`unified_tutorial`

    :ref:`postgresql_table_valued` - in the :ref:`postgresql_toplevel` documentation

    :meth:`_functions.FunctionElement.scalar_table_valued` - variant of
    :meth:`_functions.FunctionElement.table_valued` which delivers the
    complete table valued expression as a scalar column expression

    :meth:`_functions.FunctionElement.column_valued`

    :meth:`_sql.TableValuedAlias.render_derived` - renders the alias
    using a derived column clause, e.g. ``AS name(col1, col2, ...)``



Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé