MCPcopy
hub / github.com/zzzeek/sqlalchemy / column

Function column

lib/sqlalchemy/sql/_elements_constructors.py:1015–1111  ·  view source on GitHub ↗

Produce a :class:`.ColumnClause` object. The :class:`.ColumnClause` is a lightweight analogue to the :class:`_schema.Column` class. The :func:`_expression.column` function can be invoked with just a name alone, as in:: from sqlalchemy import column id, name = colu

(
    text: str,
    type_: Optional[_TypeEngineArgument[_T]] = None,
    is_literal: bool = False,
    _selectable: Optional[FromClause] = None,
)

Source from the content-addressed store, hash-verified

1013
1014
1015def column(
1016 text: str,
1017 type_: Optional[_TypeEngineArgument[_T]] = None,
1018 is_literal: bool = False,
1019 _selectable: Optional[FromClause] = None,
1020) -> ColumnClause[_T]:
1021 """Produce a :class:`.ColumnClause` object.
1022
1023 The :class:`.ColumnClause` is a lightweight analogue to the
1024 :class:`_schema.Column` class. The :func:`_expression.column`
1025 function can
1026 be invoked with just a name alone, as in::
1027
1028 from sqlalchemy import column
1029
1030 id, name = column("id"), column("name")
1031 stmt = select(id, name).select_from("user")
1032
1033 The above statement would produce SQL like:
1034
1035 .. sourcecode:: sql
1036
1037 SELECT id, name FROM user
1038
1039 Once constructed, :func:`_expression.column`
1040 may be used like any other SQL
1041 expression element such as within :func:`_expression.select`
1042 constructs::
1043
1044 from sqlalchemy.sql import column
1045
1046 id, name = column("id"), column("name")
1047 stmt = select(id, name).select_from("user")
1048
1049 The text handled by :func:`_expression.column`
1050 is assumed to be handled
1051 like the name of a database column; if the string contains mixed case,
1052 special characters, or matches a known reserved word on the target
1053 backend, the column expression will render using the quoting
1054 behavior determined by the backend. To produce a textual SQL
1055 expression that is rendered exactly without any quoting,
1056 use :func:`_expression.literal_column` instead,
1057 or pass ``True`` as the
1058 value of :paramref:`_expression.column.is_literal`. Additionally,
1059 full SQL
1060 statements are best handled using the :func:`_expression.text`
1061 construct.
1062
1063 :func:`_expression.column` can be used in a table-like
1064 fashion by combining it with the :func:`.table` function
1065 (which is the lightweight analogue to :class:`_schema.Table`
1066 ) to produce
1067 a working table construct with minimal boilerplate::
1068
1069 from sqlalchemy import table, column, select
1070
1071 user = table(
1072 "user",

Calls 1

ColumnClauseClass · 0.85