How to use the pypika.functions.Cast function in PyPika

To help you get started, we’ve selected a few PyPika examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kayak / fireant / fireant / database / mysql.py View on Github external
def to_char(self, definition):
        return fn.Cast(definition, enums.SqlTypes.CHAR)
github kayak / fireant / fireant / database / base.py View on Github external
def to_char(self, definition):
        return fn.Cast(definition, enums.SqlTypes.VARCHAR)
github tortoise / tortoise-orm / tortoise / backends / mysql / executor.py View on Github external
def mysql_insensitive_contains(field: Term, value: str) -> Criterion:
    return Like(
        functions.Upper(functions.Cast(field, SqlTypes.CHAR)),
        functions.Upper(StrWrapper(f"%{escape_like(value)}%")),
        escape="",
    )
github tortoise / tortoise-orm / tortoise / backends / mysql / executor.py View on Github external
def mysql_insensitive_starts_with(field: Term, value: str) -> Criterion:
    return Like(
        functions.Upper(functions.Cast(field, SqlTypes.CHAR)),
        functions.Upper(StrWrapper(f"{escape_like(value)}%")),
        escape="",
    )
github tortoise / tortoise-orm / tortoise / backends / mysql / executor.py View on Github external
def mysql_starts_with(field: Term, value: str) -> Criterion:
    return Like(
        functions.Cast(field, SqlTypes.CHAR), StrWrapper(f"{escape_like(value)}%"), escape=""
    )
github kayak / pypika / pypika / functions.py View on Github external
def get_special_params_sql(self, **kwargs):
        return "USING {type}".format(type=self.encoding.value)


class ToChar(Function):
    def __init__(self, term, as_type, alias=None):
        super(ToChar, self).__init__("TO_CHAR", term, as_type, alias=alias)


class Signed(Cast):
    def __init__(self, term, alias=None):
        super(Signed, self).__init__(term, SqlTypes.SIGNED, alias=alias)


class Unsigned(Cast):
    def __init__(self, term, alias=None):
        super(Unsigned, self).__init__(term, SqlTypes.UNSIGNED, alias=alias)


class Date(Function):
    def __init__(self, term, alias=None):
        super(Date, self).__init__("DATE", term, alias=alias)


class DateDiff(Function):
    def __init__(self, interval, start_date, end_date, alias=None):
        super(DateDiff, self).__init__(
            "DATEDIFF", interval, start_date, end_date, alias=alias
        )
github tortoise / tortoise-orm / tortoise / backends / mysql / executor.py View on Github external
def mysql_ends_with(field: Term, value: str) -> Criterion:
    return Like(
        functions.Cast(field, SqlTypes.CHAR), StrWrapper(f"%{escape_like(value)}"), escape=""
    )
github kayak / pypika / pypika / functions.py View on Github external
class Convert(Function):
    def __init__(self, term, encoding, alias=None):
        super(Convert, self).__init__("CONVERT", term, alias=alias)
        self.encoding = encoding

    def get_special_params_sql(self, **kwargs):
        return "USING {type}".format(type=self.encoding.value)


class ToChar(Function):
    def __init__(self, term, as_type, alias=None):
        super(ToChar, self).__init__("TO_CHAR", term, as_type, alias=alias)


class Signed(Cast):
    def __init__(self, term, alias=None):
        super(Signed, self).__init__(term, SqlTypes.SIGNED, alias=alias)


class Unsigned(Cast):
    def __init__(self, term, alias=None):
        super(Unsigned, self).__init__(term, SqlTypes.UNSIGNED, alias=alias)


class Date(Function):
    def __init__(self, term, alias=None):
        super(Date, self).__init__("DATE", term, alias=alias)


class DateDiff(Function):
    def __init__(self, interval, start_date, end_date, alias=None):
github tortoise / tortoise-orm / tortoise / fields / data.py View on Github external
def function_cast(self, term: Term) -> Term:
            return functions.Cast(term, SqlTypes.NUMERIC)
github kayak / pypika / pypika / functions.py View on Github external
def __init__(self, term, as_type, alias=None):
        super(Cast, self).__init__("CAST", term, alias=alias)
        self.as_type = as_type