cycquery.ops.CastΒΆ

class Cast(cols, type_)[source]ΒΆ

Bases: QueryOp

Cast columns to a specified type.

Currently supporting conversions to str, int, float, date, bool and timestamp.

Parameters:
  • cols (Union[str, List[str]]) – Columns to cast.

  • type – Name of type to which to convert. Must be supported.

Examples

>>> Cast("col1", "str")(table)
>>> Cast(["col1", "col2"], "int")(table)
>>> Cast("col1", "float")(table)
>>> Cast("col1", "date")(table)
>>> Cast("col1", "bool")(table)
>>> Cast("col1", "timestamp")(table)

Methods

__call__(table)[source]ΒΆ

Process the table.

Parameters:

table (Union[Select, Subquery, Table, DBTable]) – Table on which to perform the operation.

Returns:

Processed table.

Return type:

sqlalchemy.sql.selectable.Subquery