pypika.queries module

class pypika.queries.AliasedQuery(name, query=None)[source]

Bases: pypika.queries.Selectable

get_sql(**kwargs)[source]
class pypika.queries.Column(column_name, column_type=None)[source]

Bases: object

get_sql(**kwargs)[source]
class pypika.queries.CreateQueryBuilder(dialect=None)[source]

Bases: object

Query builder used to build CREATE queries.

ALIAS_QUOTE_CHAR = None
QUOTE_CHAR = '"'
SECONDARY_QUOTE_CHAR = "'"
as_select(*args, **kwargs)
columns(*args, **kwargs)
create_table(*args, **kwargs)
get_sql(**kwargs)[source]
temporary(*args, **kwargs)
class pypika.queries.Database(name, parent=None)[source]

Bases: pypika.queries.Schema

class pypika.queries.Join(item, how)[source]

Bases: object

get_sql(**kwargs)[source]
replace_table(*args, **kwargs)
validate(_from, _joins)[source]
class pypika.queries.JoinOn(item, how, criteria, collate=None)[source]

Bases: pypika.queries.Join

get_sql(**kwargs)[source]
replace_table(*args, **kwargs)
validate(_from, _joins)[source]
class pypika.queries.JoinUsing(item, how, fields)[source]

Bases: pypika.queries.Join

get_sql(**kwargs)[source]
replace_table(*args, **kwargs)
validate(_from, _joins)[source]
class pypika.queries.Joiner(query, item, how, type_label)[source]

Bases: object

cross()[source]

Return cross join

on(criterion, collate=None)[source]
on_field(*fields)[source]
using(*fields)[source]
class pypika.queries.Query[source]

Bases: object

Query is the primary class and entry point in pypika. It is used to build queries iteratively using the builder design pattern.

This class is immutable.

classmethod create_table(table)[source]

Query builder entry point. Initializes query building and sets the table name to be created. When using this function, the query becomes a CREATE statement.

Parameters:table – An instance of a Table object or a string table name.
Returns:CreateQueryBuilder
classmethod from_(table)[source]

Query builder entry point. Initializes query building and sets the table to select from. When using this function, the query becomes a SELECT query.

Parameters:table

Type: Table or str

An instance of a Table object or a string table name.

:returns QueryBuilder

classmethod into(table)[source]

Query builder entry point. Initializes query building and sets the table to insert into. When using this function, the query becomes an INSERT query.

Parameters:table

Type: Table or str

An instance of a Table object or a string table name.

:returns QueryBuilder

classmethod select(*terms)[source]

Query builder entry point. Initializes query building without a table and selects fields. Useful when testing SQL functions.

Parameters:terms

Type: list[expression]

A list of terms to select. These can be any type of int, float, str, bool, or Term. They cannot be a Field unless the function Query.from_ is called first.

:returns QueryBuilder

classmethod update(table)[source]

Query builder entry point. Initializes query building and sets the table to update. When using this function, the query becomes an UPDATE query.

Parameters:table

Type: Table or str

An instance of a Table object or a string table name.

:returns QueryBuilder

classmethod with_(table, name)[source]
class pypika.queries.QueryBuilder(dialect=None, wrap_union_queries=True, wrapper_cls=<class 'pypika.terms.ValueWrapper'>)[source]

Bases: pypika.queries.Selectable, pypika.terms.Term

Query Builder is the main class in pypika which stores the state of a query and offers functions which allow the state to be branched immutably.

ALIAS_QUOTE_CHAR = None
QUOTE_CHAR = '"'
SECONDARY_QUOTE_CHAR = "'"
columns(*args, **kwargs)
cross_join(item)[source]
delete(*args, **kwargs)
distinct(*args, **kwargs)
do_join(join)[source]
fields()[source]
force_index(*args, **kwargs)
from_(*args, **kwargs)
get_sql(with_alias=False, subquery=False, **kwargs)[source]
groupby(*args, **kwargs)
having(*args, **kwargs)
ignore(*args, **kwargs)
inner_join(item)[source]
insert(*args, **kwargs)
into(*args, **kwargs)
is_joined(table)[source]
join(*args, **kwargs)
left_join(item)[source]
limit(*args, **kwargs)
offset(*args, **kwargs)
orderby(*args, **kwargs)
outer_join(item)[source]
prewhere(*args, **kwargs)
replace(*args, **kwargs)
replace_table(*args, **kwargs)
right_join(item)[source]
rollup(*args, **kwargs)
select(*args, **kwargs)
set(*args, **kwargs)
union(*args, **kwargs)
union_all(*args, **kwargs)
update(*args, **kwargs)
where(*args, **kwargs)
with_(*args, **kwargs)
with_totals(*args, **kwargs)
class pypika.queries.Schema(name, parent=None)[source]

Bases: object

get_sql(quote_char=None, **kwargs)[source]
class pypika.queries.Selectable(alias)[source]

Bases: object

as_(*args, **kwargs)
field(name)[source]
star
class pypika.queries.Table(name, schema=None, alias=None)[source]

Bases: pypika.queries.Selectable

get_sql(**kwargs)[source]
insert(*terms)[source]

Perform an INSERT operation on the current table

Parameters:terms

Type: list[expression]

A list of terms to select. These can be any type of int, float, str, bool or any other valid data

Returns:QueryBuilder
select(*terms)[source]

Perform a SELECT operation on the current table

Parameters:terms

Type: list[expression]

A list of terms to select. These can be any type of int, float, str, bool or Term or a Field.

Returns:QueryBuilder
update()[source]

Perform an UPDATE operation on the current table

Returns:QueryBuilder
pypika.queries.make_columns(*names)[source]

Shortcut to create many columns. If names param is a tuple, the first position will refer to the name while the second will be its type. Any other data structure will be treated as a whole as the name.

pypika.queries.make_tables(*names, **kwargs)[source]

Shortcut to create many tables. If names param is a tuple, the first position will refer to the _table_name while the second will be its alias. Any other data structure will be treated as a whole as the _table_name.