0% found this document useful (0 votes)
1K views47 pages

Pypika Documentation

Python library documentation

Uploaded by

Dj Doina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views47 pages

Pypika Documentation

Python library documentation

Uploaded by

Dj Doina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

pypika Documentation

Release 0.18.4

Timothy Heys

Dec 05, 2018


Contents

1 Abstract 3

2 Contents 5
2.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Advanced Query Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Window Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.5 Extending PyPika . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.6 API Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3 Indices and tables 33

4 License 35

Python Module Index 37

i
ii
pypika Documentation, Release 0.18.4

Contents 1
pypika Documentation, Release 0.18.4

2 Contents
CHAPTER 1

Abstract

What is PyPika?
PyPika is a Python API for building SQL queries. The motivation behind PyPika is to provide a simple interface for
building SQL queries without limiting the flexibility of handwritten SQL. Designed with data analysis in mind, PyPika
leverages the builder design pattern to construct queries to avoid messy string formatting and concatenation. It is also
easily extended to take full advantage of specific features of SQL database vendors.

3
pypika Documentation, Release 0.18.4

4 Chapter 1. Abstract
CHAPTER 2

Contents

2.1 Installation

PyPika supports python 2.7 and 3.3+. It may also work on pypy, cython, and jython, but is not being tested for
these versions.
To install PyPika run the following command:

pip install pypika

2.2 Tutorial

The main classes in pypika are pypika.Query, pypika.Table, and pypika.Field.

from pypika import Query, Table, Field

2.2.1 Selecting Data

The entry point for building queries is pypika.Query. In order to select columns from a table, the table must first
be added to the query. For simple queries with only one table, tables and columns can be references using strings. For
more sophisticated queries a pypika.Table must be used.

q = Query.from_('customers').select('id', 'fname', 'lname', 'phone')

To convert the query into raw SQL, it can be cast to a string.

str(q)

Alternatively, you can use the Query.get_sql() function:

5
pypika Documentation, Release 0.18.4

q.get_sql()

Using pypika.Table

customers = Table('customers')
q = Query.from_(customers).select(customers.id, customers.fname, customers.lname,
˓→customers.phone)

Both of the above examples result in the following SQL:

SELECT id,fname,lname,phone FROM customers

Results can be ordered by using the following syntax:

from pypika import Order


Query.from_('customers').select('id', 'fname', 'lname', 'phone').orderby('id',
˓→order=Order.desc)

This results in the following SQL:

SELECT "id","fname","lname","phone" FROM "customers" ORDER BY "id" DESC

Arithmetic

Arithmetic expressions can also be constructed using pypika. Operators such as +, -, *, and / are implemented by
pypika.Field which can be used simply with a pypika.Table or directly.

from pypika import Field

q = Query.from_('account').select(
Field('revenue') - Field('cost')
)

SELECT revenue-cost FROM accounts

Using pypika.Table

accounts = Table('accounts')
q = Query.from_(accounts).select(
accounts.revenue - accounts.cost
)

SELECT revenue-cost FROM accounts

An alias can also be used for fields and expressions.

q = Query.from_(accounts).select(
(accounts.revenue - accounts.cost).as_('profit')
)

SELECT revenue-cost profit FROM accounts

More arithmetic examples

6 Chapter 2. Contents
pypika Documentation, Release 0.18.4

table = Table('table')
q = Query.from_(table).select(
table.foo + table.bar,
table.foo - table.bar,
table.foo * table.bar,
table.foo / table.bar,
(table.foo+table.bar) / table.fiz,
)

SELECT foo+bar,foo-bar,foo*bar,foo/bar,(foo+bar)/fiz FROM table

Filtering

Queries can be filtered with pypika.Criterion by using equality or inequality operators

customers = Table('customers')
q = Query.from_(customers).select(
customers.id, customers.fname, customers.lname, customers.phone
).where(
customers.lname == 'Mustermann'
)

SELECT id,fname,lname,phone FROM customers WHERE lname='Mustermann'

Query methods such as select, where, groupby, and orderby can be called multiple times. Multiple calls to the where
method will add additional conditions as

customers = Table('customers')
q = Query.from_(customers).select(
customers.id, customers.fname, customers.lname, customers.phone
).where(
customers.fname == 'Max'
).where(
customers.lname == 'Mustermann'
)

SELECT id,fname,lname,phone FROM customers WHERE fname='Max' AND lname='Mustermann'

Filters such as IN and BETWEEN are also supported

customers = Table('customers')
q = Query.from_(customers).select(
customers.id,customers.fname
).where(
customers.age[18:65] & customers.status.isin(['new', 'active'])
)

SELECT id,fname FROM customers WHERE age BETWEEN 18 AND 65 AND status IN ('new',
˓→'active')

Filtering with complex criteria can be created using boolean symbols &, |, and ^.
AND

2.2. Tutorial 7
pypika Documentation, Release 0.18.4

customers = Table('customers')
q = Query.from_(customers).select(
customers.id, customers.fname, customers.lname, customers.phone
).where(
(customers.age >= 18) & (customers.lname == 'Mustermann')
)

SELECT id,fname,lname,phone FROM customers WHERE age>=18 AND lname='Mustermann'

OR
customers = Table('customers')
q = Query.from_(customers).select(
customers.id, customers.fname, customers.lname, customers.phone
).where(
(customers.age >= 18) | (customers.lname == 'Mustermann')
)

SELECT id,fname,lname,phone FROM customers WHERE age>=18 OR lname='Mustermann'

XOR
customers = Table('customers')
q = Query.from_(customers).select(
customers.id, customers.fname, customers.lname, customers.phone
).where(
(customers.age >= 18) ^ customers.is_registered
)

SELECT id,fname,lname,phone FROM customers WHERE age>=18 XOR is_registered

Grouping and Aggregating

Grouping allows for aggregated results and works similar to SELECT clauses.
from pypika import functions as fn

customers = Table('customers')
q = Query.from_(customers).where(
customers.age >= 18
).groupby(
customers.id
).select(
customers.id, fn.Sum(customers.revenue)
)

SELECT id,SUM(revenue) FROM customers WHERE age>=18 GROUP BY id ORDER BY id ASC

After adding a GROUP BY clause to a query, the HAVING clause becomes available. The method Query.having()
takes a Criterion parameter similar to the method Query.where().
from pypika import functions as fn

payments = Table('payments')
(continues on next page)

8 Chapter 2. Contents
pypika Documentation, Release 0.18.4

(continued from previous page)


q = Query.from_(payments).where(
payments.transacted[date(2015, 1, 1):date(2016, 1, 1)]
).groupby(
payments.customer_id
).having(
fn.Sum(payments.total) >= 1000
).select(
payments.customer_id, fn.Sum(payments.total)
)

SELECT customer_id,SUM(total) FROM payments


WHERE transacted BETWEEN '2015-01-01' AND '2016-01-01'
GROUP BY customer_id HAVING SUM(total)>=1000

Joining Tables and Subqueries

Tables and subqueries can be joined to any query using the Query.join() method. Joins can be performed with
either a USING or ON clauses. The USING clause can be used when both tables/subqueries contain the same field and
the ON clause can be used with a criterion. To perform a join, ...join() can be chained but then must be followed
immediately by ...on(<criterion>) or ...using(*field).

Example of a join using ON

history, customers = Tables('history', 'customers')


q = Query.from_(history).join(
customers
).on(
history.customer_id == customers.id
).select(
history.star
).where(
customers.id == 5
)

SELECT "history".* FROM "history" JOIN "customers" ON "history"."customer_id"=


˓→"customers"."id" WHERE "customers"."id"=5

As a shortcut, the Query.join().on_field() function is provided for joining the (first) table in the FROM
clause with the joined table when the field name(s) are the same in both tables.

Example of a join using ON

history, customers = Tables('history', 'customers')


q = Query.from_(history).join(
customers
).on_field(
'customer_id', 'group'
).select(
history.star
).where(
(continues on next page)

2.2. Tutorial 9
pypika Documentation, Release 0.18.4

(continued from previous page)


customers.group == 'A'
)

SELECT "history".* FROM "history" JOIN "customers" ON "history"."customer_id"=


˓→"customers"."customer_id" AND "history"."group"="customers"."group" WHERE "customers

˓→"."group"='A'

Example of a join using USING

history, customers = Tables('history', 'customers')


q = Query.from_(history).join(
customers
).on(
'customer_id'
).select(
history.star
).where(
customers.id == 5
)

SELECT "history".* FROM "history" JOIN "customers" USING "customer_id" WHERE


˓→"customers"."id"=5

Unions

Both UNION and UNION ALL are supported. UNION DISTINCT is synonomous with “UNION‘‘ so and PyPika
does not provide a separate function for it. Unions require that queries have the same number of SELECT clauses so
trying to cast a unioned query to string with through a UnionException if the column sizes are mismatched.
To create a union query, use either the Query.union() method or + operator with two query instances. For a union
all, use Query.union_all() or the * operator.

provider_a, provider_b = Tables('provider_a', 'provider_b')


q = Query.from_(provider_a).select(
provider_a.created_time, provider_a.foo, provider_a.bar
) + Query.from_(provider_b).select(
provider_b.created_time, provider_b.fiz, provider_b.buz
)

SELECT "created_time","foo","bar" FROM "provider_a" UNION SELECT "created_time","fiz",


˓→"buz" FROM "provider_b"

Date, Time, and Intervals

Using pypika.Interval, queries can be constructed with date arithmetic. Any combination of intervals can be
used except for weeks and quarters, which must be used separately and will ignore any other values if selected.

from pypika import functions as fn

fruits = Tables('fruits')
(continues on next page)

10 Chapter 2. Contents
pypika Documentation, Release 0.18.4

(continued from previous page)


q = Query.from_(fruits) \
.select(fruits.id, fruits.name) \
.where(fruits.harvest_date + Interval(months=1) < fn.Now())

SELECT id,name FROM fruits WHERE harvest_date+INTERVAL 1 MONTH<NOW()

Tuples

Tuples are supported through the class pypika.Tuple but also through the native python tuple wherever possible.
Tuples can be used with pypika.Criterion in WHERE clauses for pairwise comparisons.

from pypika import Query, Tuple

q = Query.from_(self.table_abc) \
.select(self.table_abc.foo, self.table_abc.bar) \
.where(Tuple(self.table_abc.foo, self.table_abc.bar) == Tuple(1, 2))

SELECT "foo","bar" FROM "abc" WHERE ("foo","bar")=(1,2)

Using pypika.Tuple on both sides of the comparison is redundant and PyPika supports native python tuples.

from pypika import Query, Tuple

q = Query.from_(self.table_abc) \
.select(self.table_abc.foo, self.table_abc.bar) \
.where(Tuple(self.table_abc.foo, self.table_abc.bar) == (1, 2))

SELECT "foo","bar" FROM "abc" WHERE ("foo","bar")=(1,2)

Tuples can be used in IN clauses.

Query.from_(self.table_abc) \
.select(self.table_abc.foo, self.table_abc.bar) \
.where(Tuple(self.table_abc.foo, self.table_abc.bar).isin([(1, 1), (2, 2), (3,
˓→ 3)]))

SELECT "foo","bar" FROM "abc" WHERE ("foo","bar") IN ((1,1),(2,2),(3,3))

Strings Functions

There are several string operations and function wrappers included in PyPika. Function wrappers can be found in the
pypika.functions package. In addition, LIKE and REGEX queries are supported as well.

from pypika import functions as fn

customers = Tables('customers')
q = Query.from_(customers).select(
customers.id,
customers.fname,
customers.lname,
).where(
(continues on next page)

2.2. Tutorial 11
pypika Documentation, Release 0.18.4

(continued from previous page)


customers.lname.like('Mc%')
)

SELECT id,fname,lname FROM customers WHERE lname LIKE 'Mc%'

from pypika import functions as fn

customers = Tables('customers')
q = Query.from_(customers).select(
customers.id,
customers.fname,
customers.lname,
).where(
customers.lname.regex(r'^[abc][a-zA-Z]+&')
)

SELECT id,fname,lname FROM customers WHERE lname REGEX '^[abc][a-zA-Z]+&';

from pypika import functions as fn

customers = Tables('customers')
q = Query.from_(customers).select(
customers.id,
fn.Concat(customers.fname, ' ', customers.lname).as_('full_name'),
)

SELECT id,CONCAT(fname, ' ', lname) full_name FROM customers

Case Statements

Case statements allow fow a number of conditions to be checked sequentially and return a value for the first condition
met or otherwise a default value. The Case object can be used to chain conditions together along with their output
using the when method and to set the default value using else_.

from pypika import Case, functions as fn

customers = Tables('customers')
q = Query.from_(customers).select(
customers.id,
Case()
.when(customers.fname == "Tom", "It was Tom")
.when(customers.fname == "John", "It was John")
.else_("It was someone else.").as_('who_was_it')
)

SELECT "id",CASE WHEN "fname"='Tom' THEN 'It was Tom' WHEN "fname"='John' THEN 'It
˓→was John' ELSE 'It was someone else.' END "who_was_it" FROM "customers"

2.2.2 Inserting Data

Data can be inserted into tables either by providing the values in the query or by selecting them through another query.

12 Chapter 2. Contents
pypika Documentation, Release 0.18.4

By default, data can be inserted by providing values for all columns in the order that they are defined in the table.

Insert with values

customers = Table('customers')

q = Query.into(customers).insert(1, 'Jane', 'Doe', '[email protected]')

INSERT INTO customers VALUES (1,'Jane','Doe','[email protected]')

Multiple rows of data can be inserted either by chaining the insert function or passing multiple tuples as args.

customers = Table('customers')

q = Query.into(customers).insert(1, 'Jane', 'Doe', '[email protected]').insert(2, 'John


˓→', 'Doe', '[email protected]')

customers = Table('customers')

q = Query.into(customers).insert((1, 'Jane', 'Doe', '[email protected]'),


(2, 'John', 'Doe', '[email protected]'))

Insert with on Duplicate Key Update

customers = Table('customers')

q = Query.into(customers)\
.insert(1, 'Jane', 'Doe', '[email protected]')\
.on_duplicate_key_update(customers.email, Values(customers.email))

INSERT INTO customers VALUES (1,'Jane','Doe','[email protected]') ON DUPLICATE KEY


˓→UPDATE `email`=VALUES(`email`)

.on_duplicate_key_update works similar to .set for updating rows, additionally it provides the Values
wrapper to update to the value specified in the INSERT clause.

Insert from a SELECT Sub-query

INSERT INTO customers VALUES (1,'Jane','Doe','[email protected]'),(2,'John','Doe',


˓→'[email protected]')

To specify the columns and the order, use the columns function.

customers = Table('customers')

q = Query.into(customers).columns('id', 'fname', 'lname').insert(1, 'Jane', 'Doe')

INSERT INTO customers (id,fname,lname) VALUES (1,'Jane','Doe','[email protected]')

Inserting data with a query works the same as querying data with the additional call to the into method in the builder
chain.

2.2. Tutorial 13
pypika Documentation, Release 0.18.4

customers, customers_backup = Tables('customers', 'customers_backup')

q = Query.into(customers_backup).from_(customers).select('*')

INSERT INTO customers_backup SELECT * FROM customers

customers, customers_backup = Tables('customers', 'customers_backup')

q = Query.into(customers_backup).columns('id', 'fname', 'lname')


.from_(customers).select(customers.id, customers.fname, customers.lname)

INSERT INTO customers_backup SELECT "id", "fname", "lname" FROM customers

The syntax for joining tables is the same as when selecting data

customers, orders, orders_backup = Tables('customers', 'orders', 'orders_backup')

q = Query.into(orders_backup).columns('id', 'address', 'customer_fname', 'customer_


˓→lname')

.from_(customers)
.join(orders).on(orders.customer_id == customers.id)
.select(orders.id, customers.fname, customers.lname)

INSERT INTO "orders_backup" ("id","address","customer_fname","customer_lname")


SELECT "orders"."id","customers"."fname","customers"."lname" FROM "customers"
JOIN "orders" ON "orders"."customer_id"="customers"."id"

2.2.3 Updating Data

PyPika allows update queries to be constructed with or without where clauses.

customers = Table('customers')

Query.update(customers).set(customers.last_login, '2017-01-01 10:00:00')

Query.update(customers).set(customers.lname, smith).where(customers.id == 10)

UPDATE "customers" SET "last_login"='2017-01-01 10:00:00'

UPDATE "customers" SET "lname"='smith' WHERE "id"=10

The syntax for joining tables is the same as when selecting data

customers, profiles = Tables('customers', 'profiles')

Query.update(customers)
.join(profiles).on(profiles.customer_id == customers.id)
.set(customers.lname, profiles.lname)

UPDATE "customers"
JOIN "profiles" ON "profiles"."customer_id"="customers"."id"
SET "customers"."lname"="profiles"."lname"

14 Chapter 2. Contents
pypika Documentation, Release 0.18.4

2.3 Advanced Query Features

This section covers the range of functions that are not widely standardized across all SQL databases or meet special
needs. PyPika intends to support as many features across different platforms as possible. If there are any features
specific to a certain platform that PyPika does not support, please create a GitHub issue requesting that it be added.

2.3.1 Handling different database platforms

There can sometimes be differences between how database vendors implement SQL in their platform, for example
which quote characters are used. To ensure that the correct SQL standard is used for your platform, the platform-
specific Query classes can be used.
from pypika import MySQLQuery, MSSQLQuery, PostgreSQLQuery, OracleQuery, VerticaQuery

You can use these query classes as a drop in replacement for the default Query class shown in the other examples.
Again, if you encounter any issues specific to a platform, please create a GitHub issue on this repository.

2.3.2 GROUP BY Modifiers

The ROLLUP modifier allows for aggregating to higher levels that the given groups, called super-aggregates.
from pypika import Rollup, functions as fn

products = Table('products')

query = Query.from_(products) \
.select(products.id, products.category, fn.Sum(products.price)) \
.rollup(products.id, products.category)

SELECT "id","category",SUM("price") FROM "products" GROUP BY ROLLUP("id","category")

2.3.3 Analytic Queries

The package pypika.analytic contains analytic function wrappers. These can be used in SELECT clauses when
building queries for databases that support them. Different functions have different arguments but all require some
sort of partitioning.

NTILE and RANK

The NTILE function requires a constant integer argument while the RANK function takes no arguments. clause.
from pypika import Query, Table, analytics as an, functions as fn

store_sales_fact, date_dimension = Table('store_sales_fact', schema='store'), Table(


˓→'date_dimension')

total_sales = fn.Sum(store_sales_fact.sales_quantity).as_('TOTAL_SALES')
calendar_month_name = date_dimension.calendar_month_name.as_('MONTH')
ntile = an.NTile(4).order_by(total_sales).as_('NTILE')

query = Query.from_(store_sales_fact) \
(continues on next page)

2.3. Advanced Query Features 15


pypika Documentation, Release 0.18.4

(continued from previous page)


.join(date_dimension).using('date_key') \
.select(calendar_month_name, total_sales, ntile) \
.groupby(calendar_month_name) \
.orderby(ntile)

SELECT "date_dimension"."calendar_month_name" "MONTH",SUM("store_sales_fact"."sales_


˓→quantity") "TOTAL_SALES",NTILE(4) OVER(PARTITION BY ORDER BY SUM("store_sales_fact
˓→"."sales_quantity")) "NTILE" FROM "store"."store_sales_fact" JOIN "date_dimension"

˓→USING ("date_key") GROUP BY "date_dimension"."calendar_month_name" ORDER BY

˓→NTILE(4) OVER(PARTITION BY ORDER BY SUM("store_sales_fact"."sales_quantity"))

FIRST_VALUE and LAST_VALUE

FIRST_VALUE and LAST_VALUE both expect a single argument. They also support an additional IGNORE NULLS
clause.

from pypika import Query, Table, analytics as an

t_month = Table('t_month')

first_month = an.FirstValue(t_month.month) \
.over(t_month.season) \
.orderby(t_month.id)

last_month = an.LastValue(t_month.month) \
.over(t_month.season) \
.orderby(t_month.id) \
.ignore_nulls()

query = Query.from_(t_month) \
.select(first_month, last_month)

SELECT FIRST_VALUE("month") OVER(PARTITION BY "season" ORDER BY "id"),LAST_VALUE(


˓→"month" IGNORE NULLS) OVER(PARTITION BY "season" ORDER BY "id") FROM "t_month"

MEDIAN, AVG and STDDEV

These functions take one or more arguments

from pypika import Query, Table, analytics as an

customer_dimension = Table('customer_dimension')

median_income = an.Median(customer_dimension.annual_income).over(customer_dimension.
˓→customer_state).as_('MEDIAN')

avg_income = an.Avg(customer_dimension.annual_income).over(customer_dimension.
˓→customer_state).as_('AVG')

stddev_income = an.StdDev(customer_dimension.annual_income).over(customer_dimension.
˓→customer_state).as_('STDDEV')

query = Query.from_(customer_dimension) \
.select(median_income, avg_income, stddev_income) \
(continues on next page)

16 Chapter 2. Contents
pypika Documentation, Release 0.18.4

(continued from previous page)


.where(customer_dimension.customer_state.isin(['DC', 'WI'])) \
.orderby(customer_dimension.customer_state)

SELECT MEDIAN("annual_income") OVER(PARTITION BY "customer_state") "MEDIAN",AVG(


˓→"annual_income") OVER(PARTITION BY "customer_state") "AVG",STDDEV("annual_income")

˓→OVER(PARTITION BY "customer_state") "STDDEV" FROM "customer_dimension" WHERE

˓→"customer_state" IN ('DC','WI') ORDER BY "customer_state"

2.4 Window Frames

Functions which use window aggregation expose the functions rows() and range() with varying parameters
to define the window. Both of these functions take one or two parameters which specify the offset boundaries.
Boundaries can be set either as the current row with an.CURRENT_ROW or a value preceding or following the cur-
rent row with an.Preceding(constant_value) and an.Following(constant_value). The ranges
can be unbounded preceding or following the current row by omitting the constant_value parameter like an.
Preceding() or an.Following().
FIRST_VALUE and LAST_VALUE also support window frames.

from pypika import Query, Table, analytics as an

t_transactions = Table('t_customers')

rolling_7_sum = an.Sum(t_transactions.total) \
.over(t_transactions.item_id) \
.orderby(t_transactions.day) \
.rows(an.Preceding(7), an.CURRENT_ROW)

query = Query.from_(t_transactions) \
.select(rolling_7_sum)

SELECT SUM("total") OVER(PARTITION BY "item_id" ORDER BY "day" ROWS BETWEEN 7


˓→PRECEDING AND CURRENT ROW) FROM "t_customers"

2.5 Extending PyPika

PyPika can be extended to include additional features that are not included.
Adding functions can be achieved by extending pypika.Function.
WRITEME

2.4. Window Frames 17


pypika Documentation, Release 0.18.4

2.6 API Reference

2.6.1 pypika package

pypika.enums module

class pypika.enums.Arithmetic(*args, **kwds)


Bases: aenum.Enum
add = <Arithmetic.add: '+'>
div = <Arithmetic.div: '/'>
mul = <Arithmetic.mul: '*'>
sub = <Arithmetic.sub: '-'>
class pypika.enums.Boolean(*args, **kwds)
Bases: pypika.enums.Comparator
and_ = <Boolean.and_: 'AND'>
or_ = <Boolean.or_: 'OR'>
xor_ = <Boolean.xor_: 'XOR'>
class pypika.enums.Comparator(*args, **kwds)
Bases: aenum.Enum
class pypika.enums.DatePart(*args, **kwds)
Bases: aenum.Enum
day = <DatePart.day: 'DAY'>
hour = <DatePart.hour: 'HOUR'>
microsecond = <DatePart.microsecond: 'MICROSECOND'>
minute = <DatePart.minute: 'MINUTE'>
month = <DatePart.month: 'MONTH'>
quarter = <DatePart.quarter: 'QUARTER'>
second = <DatePart.second: 'SECOND'>
week = <DatePart.week: 'WEEK'>
year = <DatePart.year: 'YEAR'>
class pypika.enums.Dialects(*args, **kwds)
Bases: aenum.Enum
CLICKHOUSE = <Dialects.CLICKHOUSE: 'clickhouse'>
MSSQL = <Dialects.MSSQL: 'mssql'>
MYSQL = <Dialects.MYSQL: 'mysql'>
ORACLE = <Dialects.ORACLE: 'oracle'>
POSTGRESQL = <Dialects.POSTGRESQL: 'postgressql'>
REDSHIFT = <Dialects.REDSHIFT: 'redshift'>
SQLLITE = <Dialects.SQLLITE: 'sqllite'>

18 Chapter 2. Contents
pypika Documentation, Release 0.18.4

VERTICA = <Dialects.VERTICA: 'vertica'>


class pypika.enums.Equality(*args, **kwds)
Bases: pypika.enums.Comparator
eq = <Equality.eq: '='>
gt = <Equality.gt: '>'>
gte = <Equality.gte: '>='>
lt = <Equality.lt: '<'>
lte = <Equality.lte: '<='>
ne = <Equality.ne: '<>'>
class pypika.enums.JoinType(*args, **kwds)
Bases: aenum.Enum
cross = <JoinType.cross: 'CROSS'>
full_outer = <JoinType.full_outer: 'FULL OUTER'>
inner = <JoinType.inner: ''>
left = <JoinType.left: 'LEFT'>
left_outer = <JoinType.left_outer: 'LEFT OUTER'>
outer = <JoinType.outer: 'OUTER'>
right = <JoinType.right: 'RIGHT'>
right_outer = <JoinType.right_outer: 'RIGHT OUTER'>
class pypika.enums.Matching(*args, **kwds)
Bases: pypika.enums.Comparator
bin_regex = <Matching.bin_regex: ' REGEX BINARY '>
ilike = <Matching.ilike: ' ILIKE '>
like = <Matching.like: ' LIKE '>
not_ilike = <Matching.not_ilike: ' NOT ILIKE '>
not_like = <Matching.not_like: ' NOT LIKE '>
regex = <Matching.regex: ' REGEX '>
class pypika.enums.Order(*args, **kwds)
Bases: aenum.Enum
asc = <Order.asc: 'ASC'>
desc = <Order.desc: 'DESC'>
class pypika.enums.SqlType(name)

get_sql(**kwargs)
class pypika.enums.SqlTypeLength(name, length)

get_sql(**kwargs)

2.6. API Reference 19


pypika Documentation, Release 0.18.4

class pypika.enums.SqlTypes

BINARY = <pypika.enums.SqlType instance>


BOOLEAN = 'BOOLEAN'
CHAR = <pypika.enums.SqlType instance>
DATE = 'DATE'
FLOAT = 'FLOAT'
INTEGER = 'INTEGER'
LONG_VARBINARY = <pypika.enums.SqlType instance>
LONG_VARCHAR = <pypika.enums.SqlType instance>
NUMERIC = 'NUMERIC'
SIGNED = 'SIGNED'
TIME = 'TIME'
TIMESTAMP = 'TIMESTAMP'
UNSIGNED = 'UNSIGNED'
VARBINARY = <pypika.enums.SqlType instance>
VARCHAR = <pypika.enums.SqlType instance>
class pypika.enums.UnionType(*args, **kwds)
Bases: aenum.Enum
all = <UnionType.all: ' ALL'>
distinct = <UnionType.distinct: ''>

pypika.functions module

Package for SQL functions wrappers


class pypika.functions.Abs(term, alias=None)
Bases: pypika.terms.AggregateFunction
class pypika.functions.Ascii(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Avg(term, alias=None)
Bases: pypika.terms.AggregateFunction
class pypika.functions.Bin(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Cast(term, as_type, alias=None)
Bases: pypika.terms.Function
get_special_params_sql(**kwargs)
class pypika.functions.Coalesce(term, *default_values, **kwargs)
Bases: pypika.terms.Function
class pypika.functions.Concat(*terms, **kwargs)
Bases: pypika.terms.Function

20 Chapter 2. Contents
pypika Documentation, Release 0.18.4

class pypika.functions.Convert(term, encoding, alias=None)


Bases: pypika.terms.Function
get_special_params_sql(**kwargs)
class pypika.functions.Count(param, alias=None)
Bases: pypika.functions.DistinctOptionFunction
class pypika.functions.CurDate(alias=None)
Bases: pypika.terms.Function
class pypika.functions.CurTime(alias=None)
Bases: pypika.terms.Function
class pypika.functions.Date(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.DateAdd(date_part, interval, term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.DateDiff(interval, start_date, end_date, alias=None)
Bases: pypika.terms.Function
class pypika.functions.DistinctOptionFunction(name, *args, **kwargs)
Bases: pypika.terms.AggregateFunction
distinct(*args, **kwargs)
get_function_sql(**kwargs)
class pypika.functions.Extract(date_part, field, alias=None)
Bases: pypika.terms.Function
get_special_params_sql(**kwargs)
class pypika.functions.IfNull(condition, term, **kwargs)
Bases: pypika.terms.Function
class pypika.functions.Insert(term, start, stop, subterm, alias=None)
Bases: pypika.terms.Function
class pypika.functions.IsNull(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Length(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Lower(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Max(term, alias=None)
Bases: pypika.terms.AggregateFunction
class pypika.functions.Min(term, alias=None)
Bases: pypika.terms.AggregateFunction
class pypika.functions.NVL(condition, term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Now(alias=None)
Bases: pypika.terms.Function
class pypika.functions.NullIf(criterion, alias=None)
Bases: pypika.terms.Function

2.6. API Reference 21


pypika Documentation, Release 0.18.4

class pypika.functions.RegexpLike(term, pattern, modifiers=None, alias=None)


Bases: pypika.terms.Function
class pypika.functions.RegexpMatches(term, pattern, modifiers=None, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Reverse(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Signed(term, alias=None)
Bases: pypika.functions.Cast
class pypika.functions.SplitPart(term, delimiter, index, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Sqrt(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Std(term, alias=None)
Bases: pypika.terms.AggregateFunction
class pypika.functions.StdDev(term, alias=None)
Bases: pypika.terms.AggregateFunction
class pypika.functions.Substring(term, start, stop, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Sum(term, alias=None)
Bases: pypika.functions.DistinctOptionFunction
class pypika.functions.Timestamp(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.TimestampAdd(date_part, interval, term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.ToChar(term, as_type, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Trim(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.Unsigned(term, alias=None)
Bases: pypika.functions.Cast
class pypika.functions.Upper(term, alias=None)
Bases: pypika.terms.Function
class pypika.functions.UtcTimestamp(alias=None)
Bases: pypika.terms.Function

pypika.queries module

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


Bases: pypika.queries.Selectable
get_sql(**kwargs)
class pypika.queries.Join(item, how)
Bases: object
get_sql(**kwargs)

22 Chapter 2. Contents
pypika Documentation, Release 0.18.4

validate(_from, _joins)
class pypika.queries.JoinOn(item, how, criteria)
Bases: pypika.queries.Join
get_sql(**kwargs)
validate(_from, _joins)
class pypika.queries.JoinUsing(item, how, fields)
Bases: pypika.queries.Join
get_sql(**kwargs)
validate(_from, _joins)
class pypika.queries.Joiner(query, item, how, type_label)
Bases: object
cross()
Return cross join
on(criterion)
on_field(*fields)
using(*fields)
class pypika.queries.Query
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 from_(table)
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)
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)
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

2.6. API Reference 23


pypika Documentation, Release 0.18.4

classmethod update(table)
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)
class pypika.queries.QueryBuilder(quote_char=’"’, dialect=None, wrap_union_queries=True,
wrapper_cls=<class ’pypika.terms.ValueWrapper’>)
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.
columns(*args, **kwargs)
delete(*args, **kwargs)
distinct(*args, **kwargs)
do_join(join)
fields()
from_(*args, **kwargs)
get_sql(with_alias=False, subquery=False, **kwargs)
groupby(*args, **kwargs)
having(*args, **kwargs)
ignore(*args, **kwargs)
insert(*args, **kwargs)
into(*args, **kwargs)
join(*args, **kwargs)
limit(*args, **kwargs)
offset(*args, **kwargs)
orderby(*args, **kwargs)
prewhere(*args, **kwargs)
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)

24 Chapter 2. Contents
pypika Documentation, Release 0.18.4

class pypika.queries.Schema(name, parent=None)

get_sql(quote_char=None, **kwargs)
class pypika.queries.Selectable(alias)
Bases: object
field(name)
star
class pypika.queries.Table(name, schema=None, alias=None)
Bases: pypika.queries.Selectable
get_sql(quote_char=None, **kwargs)
pypika.queries.make_tables(*names, **kwargs)

pypika.terms module

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


Bases: pypika.terms.Function
is_aggregate = True
class pypika.terms.AnalyticFunction(name, *args, **kwargs)
Bases: pypika.terms.Function
get_function_sql(**kwargs)
get_partition_sql(**kwargs)
is_analytic = True
orderby(*args, **kwargs)
over(*args, **kwargs)
class pypika.terms.ArithmeticExpression(operator, left, right, alias=None)
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()
for_(*args, **kwargs)
get_sql(with_alias=False, **kwargs)
is_aggregate
mul_order = [<Arithmetic.mul: '*'>, <Arithmetic.div: '/'>]
tables_
class pypika.terms.Array(*values)
Bases: pypika.terms.Tuple
get_sql(**kwargs)
class pypika.terms.BasicCriterion(comparator, left, right, alias=None)
Bases: pypika.terms.Criterion

2.6. API Reference 25


pypika Documentation, Release 0.18.4

fields()
for_(*args, **kwargs)
get_sql(with_alias=False, **kwargs)
is_aggregate
tables_
class pypika.terms.BetweenCriterion(term, start, end, alias=None)
Bases: pypika.terms.Criterion
fields()
for_(*args, **kwargs)
get_sql(**kwargs)
tables_
class pypika.terms.Case(alias=None)
Bases: pypika.terms.Term
else_(*args, **kwargs)
fields()
get_sql(with_alias=False, **kwargs)
is_aggregate
tables_
when(*args, **kwargs)
class pypika.terms.ComplexCriterion(comparator, left, right, alias=None)
Bases: pypika.terms.BasicCriterion
fields()
get_sql(subcriterion=False, **kwargs)
needs_brackets(term)
class pypika.terms.ContainsCriterion(term, container, alias=None)
Bases: pypika.terms.Criterion
fields()
get_sql(**kwargs)
negate()
tables_
class pypika.terms.Criterion(alias=None)
Bases: pypika.terms.Term
fields()
get_sql()
class pypika.terms.Field(name, alias=None, table=None)
Bases: pypika.terms.Criterion
fields()
for_(*args, **kwargs)

26 Chapter 2. Contents
pypika Documentation, Release 0.18.4

get_sql(with_alias=False, with_namespace=False, quote_char=None, **kwargs)


tables_
class pypika.terms.Function(name, *args, **kwargs)
Bases: pypika.terms.Criterion
fields()
for_(*args, **kwargs)
get_function_sql(**kwargs)
get_special_params_sql(**kwargs)
get_sql(with_alias=False, with_namespace=False, quote_char=None, **kwargs)
is_aggregate
This is a shortcut thst 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.
tables_
class pypika.terms.IgnoreNullsAnalyticFunction(name, *args, **kwargs)
Bases: pypika.terms.AnalyticFunction
get_special_params_sql(**kwargs)
ignore_nulls(*args, **kwargs)
class pypika.terms.Interval(years=0, months=0, days=0, hours=0, minutes=0, seconds=0, mi-
croseconds=0, quarters=0, weeks=0, dialect=None)
Bases: object
fields()
get_sql(**kwargs)
labels = ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'MICROSECOND']
templates = {<Dialects.ORACLE: 'oracle'>: "INTERVAL '{expr}' {unit}", <Dialects.VERTIC
trim_pattern = <_sre.SRE_Pattern object at 0x1df3280>
units = ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'microseconds']
class pypika.terms.Mod(term, modulus, alias=None)
Bases: pypika.terms.Function
class pypika.terms.Negative(term)
Bases: pypika.terms.Term
get_sql(**kwargs)
class pypika.terms.Not(term, alias=None)
Bases: pypika.terms.Criterion
fields()
get_sql(quote_char=None, **kwargs)
tables_
class pypika.terms.NullCriterion(term, alias=None)
Bases: pypika.terms.Criterion

2.6. API Reference 27


pypika Documentation, Release 0.18.4

fields()
for_(*args, **kwargs)
get_sql(**kwargs)
tables_
class pypika.terms.NullValue(alias=None)
Bases: pypika.terms.Term
fields()
get_sql(quote_char=None, **kwargs)
class pypika.terms.Pow(term, exponent, alias=None)
Bases: pypika.terms.Function
class pypika.terms.Psuedocolumn(name)
Bases: pypika.terms.Term
Represents a pseudocolumn
to_sql(**kwargs)
class pypika.terms.Rollup(*terms)
Bases: pypika.terms.Function
class pypika.terms.Star(table=None)
Bases: pypika.terms.Field
get_sql(with_alias=False, with_namespace=False, quote_char=None, **kwargs)
class pypika.terms.Term(alias=None)
Bases: object
as_(*args, **kwargs)
between(lower, upper)
bin_regex(pattern)
eq(other)
fields()
for_(table)
Replaces the tables of this term for the table parameter provided. The base implementation returns self
because not all terms have a table property.
Parameters table – The table to replace with.
Returns Self.
get_sql()
gt(other)
gte(other)
ilike(expr)
is_aggregate = False
isin(arg)
isnull()
like(expr)

28 Chapter 2. Contents
pypika Documentation, Release 0.18.4

lt(other)
lte(other)
ne(other)
negate()
not_ilike(expr)
not_like(expr)
notin(arg)
notnull()
regex(pattern)
tables_
wrap_constant(val)
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.
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.
class pypika.terms.Tuple(*values)
Bases: pypika.terms.Term
fields()
get_sql(**kwargs)
class pypika.terms.ValueWrapper(value, alias=None)
Bases: pypika.terms.Term
fields()
get_sql(quote_char=None, **kwargs)
is_aggregate = None
class pypika.terms.Values(field)
Bases: pypika.terms.Term
get_sql(quote_char=None, **kwargs)
class pypika.terms.WindowFrameAnalyticFunction(name, *args, **kwargs)
Bases: pypika.terms.AnalyticFunction
class Edge(value=None)
get_frame_sql()
get_partition_sql(**kwargs)
range(*args, **kwargs)
rows(*args, **kwargs)

2.6. API Reference 29


pypika Documentation, Release 0.18.4

pypika.utils module

exception pypika.utils.CaseException
Bases: exceptions.Exception
exception pypika.utils.DialectNotSupported
Bases: exceptions.Exception
exception pypika.utils.GroupingException
Bases: exceptions.Exception
exception pypika.utils.JoinException
Bases: exceptions.Exception
exception pypika.utils.QueryException
Bases: exceptions.Exception
exception pypika.utils.RollupException
Bases: exceptions.Exception
exception pypika.utils.UnionException
Bases: exceptions.Exception
pypika.utils.alias_sql(sql, alias, quote_char=None)
pypika.utils.builder(func)
Decorator for wrapper “builder” functions. These are functions on the Query class or other classes used for
building queries which mutate the query and return self. To make the build functions immutable, this decorator
is used which will deepcopy the current instance. This decorator will return the return value of the inner function
or the new copy of the instance. The inner function does not need to return self.
pypika.utils.format_quotes(value, quote_char)
pypika.utils.ignore_copy(func)
Decorator for wrapping the __getattr__ function for classes that are copied via deepcopy. This prevents infinite
recursion caused by deepcopy looking for magic functions in the class. Any class implementing __getattr__ that
is meant to be deepcopy’d should use this decorator.
deepcopy is used by pypika in builder functions (decorated by @builder) to make the results immutable. Any
data model type class (stored in the Query instance) is copied.
pypika.utils.resolve_is_aggregate(values)
Resolves the is_aggregate flag for an expression that contains multiple terms. This works like a voter system,
each term votes True or False or abstains with None.
Parameters values – A list of booleans (or None) for each term in the expression
Returns If all values are True or None, True is returned. If all values are None, None is returned.
Otherwise, False is returned.

Module contents

PyPika is divided into a couple of modules, primarily the queries and terms modules.

pypika.queries

This is where the Query class can be found which is the core class in PyPika. Also, other top level classes such as
Table can be found here. Query is a container that holds all of the Term types together and also serializes the
builder to a string.

30 Chapter 2. Contents
pypika Documentation, Release 0.18.4

pypika.terms

This module contains the classes which represent individual parts of queries that extend the Term base class.

pypika.functions

Wrappers for common SQL functions are stored in this package.

pypika.enums

Enumerated values are kept in this package which are used as options for Queries and Terms.

pypika.utils

This contains all of the utility classes such as exceptions and decorators.

2.6. API Reference 31


pypika Documentation, Release 0.18.4

32 Chapter 2. Contents
CHAPTER 3

Indices and tables

• genindex
• modindex

33
pypika Documentation, Release 0.18.4

34 Chapter 3. Indices and tables


CHAPTER 4

License

Copyright 2016 KAYAK Germany, GmbH


Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
“AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under the License.
Crafted with in Berlin.

35
pypika Documentation, Release 0.18.4

36 Chapter 4. License
Python Module Index

p
pypika, 30
pypika.enums, 18
pypika.functions, 20
pypika.queries, 22
pypika.terms, 25
pypika.utils, 30

37
pypika Documentation, Release 0.18.4

38 Python Module Index


Index

A Comparator (class in pypika.enums), 18


Abs (class in pypika.functions), 20 ComplexCriterion (class in pypika.terms), 26
add (pypika.enums.Arithmetic attribute), 18 Concat (class in pypika.functions), 20
add_order (pypika.terms.ArithmeticExpression attribute), ContainsCriterion (class in pypika.terms), 26
25 Convert (class in pypika.functions), 20
AggregateFunction (class in pypika.terms), 25 Count (class in pypika.functions), 21
alias_sql() (in module pypika.utils), 30 Criterion (class in pypika.terms), 26
AliasedQuery (class in pypika.queries), 22 cross (pypika.enums.JoinType attribute), 19
all (pypika.enums.UnionType attribute), 20 cross() (pypika.queries.Joiner method), 23
AnalyticFunction (class in pypika.terms), 25 CurDate (class in pypika.functions), 21
and_ (pypika.enums.Boolean attribute), 18 CurTime (class in pypika.functions), 21
Arithmetic (class in pypika.enums), 18
ArithmeticExpression (class in pypika.terms), 25
D
Array (class in pypika.terms), 25 Date (class in pypika.functions), 21
as_() (pypika.terms.Term method), 28 DATE (pypika.enums.SqlTypes attribute), 20
asc (pypika.enums.Order attribute), 19 DateAdd (class in pypika.functions), 21
Ascii (class in pypika.functions), 20 DateDiff (class in pypika.functions), 21
Avg (class in pypika.functions), 20 DatePart (class in pypika.enums), 18
day (pypika.enums.DatePart attribute), 18
B delete() (pypika.queries.QueryBuilder method), 24
desc (pypika.enums.Order attribute), 19
BasicCriterion (class in pypika.terms), 25
DialectNotSupported, 30
between() (pypika.terms.Term method), 28
Dialects (class in pypika.enums), 18
BetweenCriterion (class in pypika.terms), 26
distinct (pypika.enums.UnionType attribute), 20
Bin (class in pypika.functions), 20
distinct() (pypika.functions.DistinctOptionFunction
bin_regex (pypika.enums.Matching attribute), 19
method), 21
bin_regex() (pypika.terms.Term method), 28
distinct() (pypika.queries.QueryBuilder method), 24
BINARY (pypika.enums.SqlTypes attribute), 20
DistinctOptionFunction (class in pypika.functions), 21
Boolean (class in pypika.enums), 18
div (pypika.enums.Arithmetic attribute), 18
BOOLEAN (pypika.enums.SqlTypes attribute), 20
do_join() (pypika.queries.QueryBuilder method), 24
builder() (in module pypika.utils), 30
E
C
else_() (pypika.terms.Case method), 26
Case (class in pypika.terms), 26 eq (pypika.enums.Equality attribute), 19
CaseException, 30 eq() (pypika.terms.Term method), 28
Cast (class in pypika.functions), 20 Equality (class in pypika.enums), 19
CHAR (pypika.enums.SqlTypes attribute), 20 Extract (class in pypika.functions), 21
CLICKHOUSE (pypika.enums.Dialects attribute), 18
Coalesce (class in pypika.functions), 20 F
columns() (pypika.queries.QueryBuilder method), 24 Field (class in pypika.terms), 26

39
pypika Documentation, Release 0.18.4

field() (pypika.queries.Selectable method), 25 method), 27


fields() (pypika.queries.QueryBuilder method), 24 get_sql() (pypika.enums.SqlType method), 19
fields() (pypika.terms.ArithmeticExpression method), 25 get_sql() (pypika.enums.SqlTypeLength method), 19
fields() (pypika.terms.BasicCriterion method), 25 get_sql() (pypika.queries.AliasedQuery method), 22
fields() (pypika.terms.BetweenCriterion method), 26 get_sql() (pypika.queries.Join method), 22
fields() (pypika.terms.Case method), 26 get_sql() (pypika.queries.JoinOn method), 23
fields() (pypika.terms.ComplexCriterion method), 26 get_sql() (pypika.queries.JoinUsing method), 23
fields() (pypika.terms.ContainsCriterion method), 26 get_sql() (pypika.queries.QueryBuilder method), 24
fields() (pypika.terms.Criterion method), 26 get_sql() (pypika.queries.Schema method), 25
fields() (pypika.terms.Field method), 26 get_sql() (pypika.queries.Table method), 25
fields() (pypika.terms.Function method), 27 get_sql() (pypika.terms.ArithmeticExpression method),
fields() (pypika.terms.Interval method), 27 25
fields() (pypika.terms.Not method), 27 get_sql() (pypika.terms.Array method), 25
fields() (pypika.terms.NullCriterion method), 27 get_sql() (pypika.terms.BasicCriterion method), 26
fields() (pypika.terms.NullValue method), 28 get_sql() (pypika.terms.BetweenCriterion method), 26
fields() (pypika.terms.Term method), 28 get_sql() (pypika.terms.Case method), 26
fields() (pypika.terms.Tuple method), 29 get_sql() (pypika.terms.ComplexCriterion method), 26
fields() (pypika.terms.ValueWrapper method), 29 get_sql() (pypika.terms.ContainsCriterion method), 26
FLOAT (pypika.enums.SqlTypes attribute), 20 get_sql() (pypika.terms.Criterion method), 26
for_() (pypika.terms.ArithmeticExpression method), 25 get_sql() (pypika.terms.Field method), 26
for_() (pypika.terms.BasicCriterion method), 26 get_sql() (pypika.terms.Function method), 27
for_() (pypika.terms.BetweenCriterion method), 26 get_sql() (pypika.terms.Interval method), 27
for_() (pypika.terms.Field method), 26 get_sql() (pypika.terms.Negative method), 27
for_() (pypika.terms.Function method), 27 get_sql() (pypika.terms.Not method), 27
for_() (pypika.terms.NullCriterion method), 28 get_sql() (pypika.terms.NullCriterion method), 28
for_() (pypika.terms.Term method), 28 get_sql() (pypika.terms.NullValue method), 28
format_quotes() (in module pypika.utils), 30 get_sql() (pypika.terms.Star method), 28
from_() (pypika.queries.Query class method), 23 get_sql() (pypika.terms.Term method), 28
from_() (pypika.queries.QueryBuilder method), 24 get_sql() (pypika.terms.Tuple method), 29
full_outer (pypika.enums.JoinType attribute), 19 get_sql() (pypika.terms.Values method), 29
Function (class in pypika.terms), 27 get_sql() (pypika.terms.ValueWrapper method), 29
groupby() (pypika.queries.QueryBuilder method), 24
G GroupingException, 30
get_frame_sql() (pypika.terms.WindowFrameAnalyticFunction gt (pypika.enums.Equality attribute), 19
method), 29 gt() (pypika.terms.Term method), 28
get_function_sql() (pypika.functions.DistinctOptionFunctiongte (pypika.enums.Equality attribute), 19
method), 21 gte() (pypika.terms.Term method), 28
get_function_sql() (pypika.terms.AnalyticFunction
method), 25 H
get_function_sql() (pypika.terms.Function method), 27 having() (pypika.queries.QueryBuilder method), 24
get_partition_sql() (pypika.terms.AnalyticFunction hour (pypika.enums.DatePart attribute), 18
method), 25
I
get_partition_sql() (pypika.terms.WindowFrameAnalyticFunction
method), 29 IfNull (class in pypika.functions), 21
get_special_params_sql() (pypika.functions.Cast ignore() (pypika.queries.QueryBuilder method), 24
method), 20 ignore_copy() (in module pypika.utils), 30
get_special_params_sql() (pypika.functions.Convert ignore_nulls() (pypika.terms.IgnoreNullsAnalyticFunction
method), 21 method), 27
get_special_params_sql() (pypika.functions.Extract IgnoreNullsAnalyticFunction (class in pypika.terms), 27
method), 21 ilike (pypika.enums.Matching attribute), 19
get_special_params_sql() (pypika.terms.Function ilike() (pypika.terms.Term method), 28
method), 27 inner (pypika.enums.JoinType attribute), 19
get_special_params_sql() Insert (class in pypika.functions), 21
(pypika.terms.IgnoreNullsAnalyticFunction insert() (pypika.queries.QueryBuilder method), 24

40 Index
pypika Documentation, Release 0.18.4

INTEGER (pypika.enums.SqlTypes attribute), 20 MSSQL (pypika.enums.Dialects attribute), 18


Interval (class in pypika.terms), 27 mul (pypika.enums.Arithmetic attribute), 18
into() (pypika.queries.Query class method), 23 mul_order (pypika.terms.ArithmeticExpression attribute),
into() (pypika.queries.QueryBuilder method), 24 25
is_aggregate (pypika.terms.AggregateFunction attribute), MYSQL (pypika.enums.Dialects attribute), 18
25
is_aggregate (pypika.terms.ArithmeticExpression at- N
tribute), 25 ne (pypika.enums.Equality attribute), 19
is_aggregate (pypika.terms.BasicCriterion attribute), 26 ne() (pypika.terms.Term method), 29
is_aggregate (pypika.terms.Case attribute), 26 needs_brackets() (pypika.terms.ComplexCriterion
is_aggregate (pypika.terms.Function attribute), 27 method), 26
is_aggregate (pypika.terms.Term attribute), 28 negate() (pypika.terms.ContainsCriterion method), 26
is_aggregate (pypika.terms.ValueWrapper attribute), 29 negate() (pypika.terms.Term method), 29
is_analytic (pypika.terms.AnalyticFunction attribute), 25 Negative (class in pypika.terms), 27
isin() (pypika.terms.Term method), 28 Not (class in pypika.terms), 27
IsNull (class in pypika.functions), 21 not_ilike (pypika.enums.Matching attribute), 19
isnull() (pypika.terms.Term method), 28 not_ilike() (pypika.terms.Term method), 29
not_like (pypika.enums.Matching attribute), 19
J not_like() (pypika.terms.Term method), 29
Join (class in pypika.queries), 22 notin() (pypika.terms.Term method), 29
join() (pypika.queries.QueryBuilder method), 24 notnull() (pypika.terms.Term method), 29
Joiner (class in pypika.queries), 23 Now (class in pypika.functions), 21
JoinException, 30 NullCriterion (class in pypika.terms), 27
JoinOn (class in pypika.queries), 23 NullIf (class in pypika.functions), 21
JoinType (class in pypika.enums), 19 NullValue (class in pypika.terms), 28
JoinUsing (class in pypika.queries), 23 NUMERIC (pypika.enums.SqlTypes attribute), 20
NVL (class in pypika.functions), 21
L
labels (pypika.terms.Interval attribute), 27 O
left (pypika.enums.JoinType attribute), 19 offset() (pypika.queries.QueryBuilder method), 24
left_outer (pypika.enums.JoinType attribute), 19 on() (pypika.queries.Joiner method), 23
Length (class in pypika.functions), 21 on_field() (pypika.queries.Joiner method), 23
like (pypika.enums.Matching attribute), 19 or_ (pypika.enums.Boolean attribute), 18
like() (pypika.terms.Term method), 28 ORACLE (pypika.enums.Dialects attribute), 18
limit() (pypika.queries.QueryBuilder method), 24 Order (class in pypika.enums), 19
LONG_VARBINARY (pypika.enums.SqlTypes at- orderby() (pypika.queries.QueryBuilder method), 24
tribute), 20 orderby() (pypika.terms.AnalyticFunction method), 25
LONG_VARCHAR (pypika.enums.SqlTypes attribute), outer (pypika.enums.JoinType attribute), 19
20 over() (pypika.terms.AnalyticFunction method), 25
Lower (class in pypika.functions), 21
lt (pypika.enums.Equality attribute), 19 P
lt() (pypika.terms.Term method), 28 POSTGRESQL (pypika.enums.Dialects attribute), 18
lte (pypika.enums.Equality attribute), 19 Pow (class in pypika.terms), 28
lte() (pypika.terms.Term method), 29 prewhere() (pypika.queries.QueryBuilder method), 24
Psuedocolumn (class in pypika.terms), 28
M pypika (module), 30
make_tables() (in module pypika.queries), 25 pypika.enums (module), 18
Matching (class in pypika.enums), 19 pypika.functions (module), 20
Max (class in pypika.functions), 21 pypika.queries (module), 22
microsecond (pypika.enums.DatePart attribute), 18 pypika.terms (module), 25
Min (class in pypika.functions), 21 pypika.utils (module), 30
minute (pypika.enums.DatePart attribute), 18
Mod (class in pypika.terms), 27 Q
month (pypika.enums.DatePart attribute), 18 quarter (pypika.enums.DatePart attribute), 18

Index 41
pypika Documentation, Release 0.18.4

Query (class in pypika.queries), 23 tables_ (pypika.terms.Not attribute), 27


QueryBuilder (class in pypika.queries), 24 tables_ (pypika.terms.NullCriterion attribute), 28
QueryException, 30 tables_ (pypika.terms.Term attribute), 29
templates (pypika.terms.Interval attribute), 27
R Term (class in pypika.terms), 28
range() (pypika.terms.WindowFrameAnalyticFunction TIME (pypika.enums.SqlTypes attribute), 20
method), 29 Timestamp (class in pypika.functions), 22
REDSHIFT (pypika.enums.Dialects attribute), 18 TIMESTAMP (pypika.enums.SqlTypes attribute), 20
regex (pypika.enums.Matching attribute), 19 TimestampAdd (class in pypika.functions), 22
regex() (pypika.terms.Term method), 29 to_sql() (pypika.terms.Psuedocolumn method), 28
RegexpLike (class in pypika.functions), 21 ToChar (class in pypika.functions), 22
RegexpMatches (class in pypika.functions), 22 Trim (class in pypika.functions), 22
resolve_is_aggregate() (in module pypika.utils), 30 trim_pattern (pypika.terms.Interval attribute), 27
Reverse (class in pypika.functions), 22 Tuple (class in pypika.terms), 29
right (pypika.enums.JoinType attribute), 19
right_outer (pypika.enums.JoinType attribute), 19 U
Rollup (class in pypika.terms), 28 union() (pypika.queries.QueryBuilder method), 24
rollup() (pypika.queries.QueryBuilder method), 24 union_all() (pypika.queries.QueryBuilder method), 24
RollupException, 30 UnionException, 30
rows() (pypika.terms.WindowFrameAnalyticFunction UnionType (class in pypika.enums), 20
method), 29 units (pypika.terms.Interval attribute), 27
Unsigned (class in pypika.functions), 22
S UNSIGNED (pypika.enums.SqlTypes attribute), 20
Schema (class in pypika.queries), 24 update() (pypika.queries.Query class method), 23
second (pypika.enums.DatePart attribute), 18 update() (pypika.queries.QueryBuilder method), 24
select() (pypika.queries.Query class method), 23 Upper (class in pypika.functions), 22
select() (pypika.queries.QueryBuilder method), 24 using() (pypika.queries.Joiner method), 23
Selectable (class in pypika.queries), 25 UtcTimestamp (class in pypika.functions), 22
set() (pypika.queries.QueryBuilder method), 24
Signed (class in pypika.functions), 22 V
SIGNED (pypika.enums.SqlTypes attribute), 20 validate() (pypika.queries.Join method), 22
SplitPart (class in pypika.functions), 22 validate() (pypika.queries.JoinOn method), 23
SQLLITE (pypika.enums.Dialects attribute), 18 validate() (pypika.queries.JoinUsing method), 23
SqlType (class in pypika.enums), 19 Values (class in pypika.terms), 29
SqlTypeLength (class in pypika.enums), 19 ValueWrapper (class in pypika.terms), 29
SqlTypes (class in pypika.enums), 19 VARBINARY (pypika.enums.SqlTypes attribute), 20
Sqrt (class in pypika.functions), 22 VARCHAR (pypika.enums.SqlTypes attribute), 20
Star (class in pypika.terms), 28 VERTICA (pypika.enums.Dialects attribute), 18
star (pypika.queries.Selectable attribute), 25
Std (class in pypika.functions), 22 W
StdDev (class in pypika.functions), 22 week (pypika.enums.DatePart attribute), 18
sub (pypika.enums.Arithmetic attribute), 18 when() (pypika.terms.Case method), 26
Substring (class in pypika.functions), 22 where() (pypika.queries.QueryBuilder method), 24
Sum (class in pypika.functions), 22 WindowFrameAnalyticFunction (class in pypika.terms),
29
T WindowFrameAnalyticFunction.Edge (class in
Table (class in pypika.queries), 25 pypika.terms), 29
tables_ (pypika.terms.ArithmeticExpression attribute), 25 with_() (pypika.queries.Query class method), 24
tables_ (pypika.terms.BasicCriterion attribute), 26 with_() (pypika.queries.QueryBuilder method), 24
tables_ (pypika.terms.BetweenCriterion attribute), 26 with_totals() (pypika.queries.QueryBuilder method), 24
tables_ (pypika.terms.Case attribute), 26 wrap_constant() (pypika.terms.Term method), 29
tables_ (pypika.terms.ContainsCriterion attribute), 26
tables_ (pypika.terms.Field attribute), 27 X
tables_ (pypika.terms.Function attribute), 27 xor_ (pypika.enums.Boolean attribute), 18

42 Index
pypika Documentation, Release 0.18.4

Y
year (pypika.enums.DatePart attribute), 18

Index 43

You might also like