pypika.terms module

class pypika.terms.AggregateFunction(name, *args, **kwargs)[source]

Bases: pypika.terms.Function

is_aggregate = True
class pypika.terms.AnalyticFunction(name, *args, **kwargs)[source]

Bases: pypika.terms.Function

get_function_sql(**kwargs)[source]
get_partition_sql(**kwargs)[source]
is_analytic = True
orderby(*args, **kwargs)
over(*args, **kwargs)
class pypika.terms.ArithmeticExpression(operator, left, right, alias=None)[source]

Bases: pypika.terms.Term

Wrapper for an arithmetic function. Can be simple with two terms or complex with nested terms. Order of operations are also preserved.

add_order = [<Arithmetic.add: '+'>, <Arithmetic.sub: '-'>]
fields()[source]
get_sql(with_alias=False, **kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

mul_order = [<Arithmetic.mul: '*'>, <Arithmetic.div: '/'>]
replace_table(*args, **kwargs)
tables_
class pypika.terms.Array(*values)[source]

Bases: pypika.terms.Tuple

get_sql(**kwargs)[source]
class pypika.terms.BasicCriterion(comparator, left, right, alias=None)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(quote_char='"', with_alias=False, **kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

replace_table(*args, **kwargs)
tables_
class pypika.terms.BetweenCriterion(term, start, end, alias=None)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(**kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

replace_table(*args, **kwargs)
tables_
class pypika.terms.BitwiseAndCriterion(term, value, alias=None)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(**kwargs)[source]
replace_table(*args, **kwargs)
tables_
class pypika.terms.Bracket(term)[source]

Bases: pypika.terms.Tuple

get_sql(**kwargs)[source]
class pypika.terms.Case(alias=None)[source]

Bases: pypika.terms.Term

else_(*args, **kwargs)
fields()[source]
get_sql(with_alias=False, **kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

replace_table(*args, **kwargs)
tables_
when(*args, **kwargs)
class pypika.terms.ComplexCriterion(comparator, left, right, alias=None)[source]

Bases: pypika.terms.BasicCriterion

fields()[source]
get_sql(subcriterion=False, **kwargs)[source]
needs_brackets(term)[source]
class pypika.terms.ContainsCriterion(term, container, alias=None)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(subquery=None, **kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

negate()[source]
replace_table(*args, **kwargs)
tables_
class pypika.terms.Criterion(alias=None)[source]

Bases: pypika.terms.Term

static all(terms=())[source]
static any(terms=())[source]
fields()[source]
get_sql()[source]
class pypika.terms.CustomFunction(name, params=None)[source]

Bases: object

class pypika.terms.EmptyCriterion[source]

Bases: object

is_aggregate = None
tables_ = {}
class pypika.terms.Field(name, alias=None, table=None)[source]

Bases: pypika.terms.Criterion, pypika.terms.JSON

fields()[source]
get_sql(with_alias=False, with_namespace=False, quote_char=None, secondary_quote_char="'", **kwargs)[source]
replace_table(*args, **kwargs)
tables_
class pypika.terms.Function(name, *args, **kwargs)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_function_sql(**kwargs)[source]
get_special_params_sql(**kwargs)[source]
get_sql(with_alias=False, with_namespace=False, quote_char=None, dialect=None, **kwargs)[source]
is_aggregate

This is a shortcut that assumes if a function has a single argument and that argument is aggregated, then this function is also aggregated. A more sophisticated approach is needed, however it is unclear how that might work. :returns:

True if the function accepts one argument and that argument is aggregate.
replace_table(*args, **kwargs)
tables_
class pypika.terms.IgnoreNullsAnalyticFunction(name, *args, **kwargs)[source]

Bases: pypika.terms.AnalyticFunction

get_special_params_sql(**kwargs)[source]
ignore_nulls(*args, **kwargs)
class pypika.terms.Index(name, alias=None)[source]

Bases: pypika.terms.Term

get_sql(quote_char=None, **kwargs)[source]
class pypika.terms.Interval(years=0, months=0, days=0, hours=0, minutes=0, seconds=0, microseconds=0, quarters=0, weeks=0, dialect=None)[source]

Bases: object

fields()[source]
get_sql(**kwargs)[source]
labels = ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'MICROSECOND']
tables_
templates = {<Dialects.MYSQL: 'mysql'>: 'INTERVAL {expr} {unit}', <Dialects.POSTGRESQL: 'postgressql'>: "INTERVAL '{expr} {unit}'", <Dialects.REDSHIFT: 'redshift'>: "INTERVAL '{expr} {unit}'", <Dialects.VERTICA: 'vertica'>: "INTERVAL '{expr} {unit}'", <Dialects.ORACLE: 'oracle'>: "INTERVAL '{expr}' {unit}"}
trim_pattern = re.compile('(^0+\\.)|(\\.0+$)|(^[0\\-.: ]+[\\-: ])|([\\-:. ][0\\-.: ]+$)')
units = ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'microseconds']
class pypika.terms.JSON(value, alias=None)[source]

Bases: pypika.terms.Term

contained_by(other)[source]
contains(other)[source]
get_json_value(key_or_index: Union[str, int])[source]
get_path_json_value(path_json: str)[source]
get_path_text_value(path_json: str)[source]
get_sql(secondary_quote_char="'", **kwargs)[source]
get_text_value(key_or_index: Union[str, int])[source]
has_any_keys(other: Iterable[T_co])[source]
has_key(other)[source]
has_keys(other: Iterable[T_co])[source]
table = None
class pypika.terms.Mod(term, modulus, alias=None)[source]

Bases: pypika.terms.Function

class pypika.terms.Negative(term)[source]

Bases: pypika.terms.Term

get_sql(**kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

class pypika.terms.NestedCriterion(comparator, nested_comparator, left, right, nested, alias=None)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(with_alias=False, **kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

replace_table(*args, **kwargs)
tables_
class pypika.terms.Not(term, alias=None)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(**kwargs)[source]
replace_table(*args, **kwargs)
tables_
class pypika.terms.NullCriterion(term, alias=None)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(**kwargs)[source]
replace_table(*args, **kwargs)
tables_
class pypika.terms.NullValue(alias=None)[source]

Bases: pypika.terms.Term

fields()[source]
get_sql(**kwargs)[source]
class pypika.terms.Parameter(placeholder)[source]

Bases: pypika.terms.Term

fields()[source]
get_sql(**kwargs)[source]
is_aggregate = None
class pypika.terms.Pow(term, exponent, alias=None)[source]

Bases: pypika.terms.Function

class pypika.terms.PseudoColumn(name)[source]

Bases: pypika.terms.Term

Represents a pseudo column (a “column” which yields a value when selected but is not actually a real table column).

fields()[source]
get_sql(**kwargs)[source]
class pypika.terms.Rollup(*terms)[source]

Bases: pypika.terms.Function

class pypika.terms.Star(table=None)[source]

Bases: pypika.terms.Field

get_sql(with_alias=False, with_namespace=False, quote_char=None, **kwargs)[source]
tables_
class pypika.terms.Term(alias=None)[source]

Bases: object

as_(*args, **kwargs)
between(lower, upper)[source]
bin_regex(pattern)[source]
bitwiseand(value)[source]
eq(other)[source]
fields()[source]
get_sql(**kwargs)[source]
gt(other)[source]
gte(other)[source]
ilike(expr)[source]
is_aggregate = False
isin(arg)[source]
isnull()[source]
like(expr)[source]
lt(other)[source]
lte(other)[source]
ne(other)[source]
negate()[source]
not_ilike(expr)[source]
not_like(expr)[source]
notin(arg)[source]
notnull()[source]
regex(pattern)[source]
replace_table(current_table, new_table)[source]

Replaces all occurrences of the specified table with the new table. Useful when reusing fields across queries. The base implementation returns self because not all terms have a table property.

Parameters:
  • current_table – The table to be replaced.
  • new_table – The table to replace with.
Returns:

Self.

tables_
static wrap_constant(val, wrapper_cls=None)[source]

Used for wrapping raw inputs such as numbers in Criterions and Operator.

For example, the expression F(‘abc’)+1 stores the integer part in a ValueWrapper object.

Parameters:
  • val – Any value.
  • wrapper_cls – A pypika class which wraps a constant value so it can be handled as a component of the query.
Returns:

Raw string, number, or decimal values will be returned in a ValueWrapper. Fields and other parts of the querybuilder will be returned as inputted.

static wrap_json(val, wrapper_cls=None)[source]
class pypika.terms.Tuple(*values)[source]

Bases: pypika.terms.Criterion

fields()[source]
get_sql(**kwargs)[source]
is_aggregate

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

replace_table(*args, **kwargs)
class pypika.terms.ValueWrapper(value, alias=None)[source]

Bases: pypika.terms.Term

fields()[source]
get_sql(quote_char=None, secondary_quote_char="'", **kwargs)[source]
get_value_sql(**kwargs)[source]
is_aggregate = None
class pypika.terms.Values(field)[source]

Bases: pypika.terms.Term

get_sql(quote_char=None, **kwargs)[source]
class pypika.terms.WindowFrameAnalyticFunction(name, *args, **kwargs)[source]

Bases: pypika.terms.AnalyticFunction

class Edge(value=None)[source]

Bases: object

get_frame_sql()[source]
get_partition_sql(**kwargs)[source]
range(*args, **kwargs)
rows(*args, **kwargs)