Ecto.Query.API

The Query API available by default in Ecto queries.

All queries in Ecto are typesafe and this module defines all database functions based on their type. Note that this module defines only the API, each database adapter still needs to support the functions outlined here.

Source

Summary

left != right

Inequality

left * right

Multiplication of numbers

left ++ right

List concatenation

+arg

Positive number

left + right

Addition of numbers

-arg

Negate number

left - right

Subtraction of numbers

left .. right

Range from left to right

left / right

Division of numbers

left < right

Left less than right

left <= right

Left less than or equal to right

left <> right

Binary and string concatenation

left == right

Equality

left > right

Left greater than right

left >= right

Left greater than or equal to right

left and right

Boolean and

avg(numbers)

Aggregate function, averages the given field over the current group

binary(string)

Casts a binary literal to a binary type. By default a binary literal is of the string type

count(arg)

Aggregate function, counts the number of occurrences of the given field in the current group

date(datetime)

Extract date from datetime

datetime(date, time)

Create a datetime from a date and a time

div(left, right)

Integer division

downcase(string)

Downcase string

field(var, atom)

References a field. This can be used when a field needs to be dynamically referenced

ilike(left, right)

Case-insensitive pattern match

left in right

Return true if left is in right array, false otherwise

is_nil(arg)

Returns true if argument is nil

like(left, right)

Case-sensitive pattern match

localtimestamp()

Returns the current local date and time

max(numbers)

Aggregate function, the maximum number of the given field in the current group

min(numbers)

Aggregate function, the minimum number of the given field in the current group

not arg

Boolean not

now()

Returns the current date and time

left or right

Boolean or

pow(base, exp)

base to the power of exp

random()

Random float number from 0.0 to 1.0 including

rem(left, right)

Integer remainder of division

round(number)

Round number to closest integer

round(x0, x1)
sum(numbers)

Aggregate function, sums the given field over the current group

time(datetime)

Extract time from datetime

time_add(left, right)

Addition of datetime’s with interval’s

time_sub(left, right)

Subtraction of datetime’s with interval’s

upcase(string)

Upcase string

uuid(string)

Casts a binary literal to a uuid type. By default a binary literal is of the string type

Functions

left != right

Inequality.

Source
left * right

Multiplication of numbers.

Source
+arg

Positive number.

Source
left + right

Addition of numbers.

Source
left ++ right

List concatenation.

Source
-arg

Negate number.

Source
left - right

Subtraction of numbers.

Source
left .. right

Range from left to right.

Source
left / right

Division of numbers.

Source
left < right

Left less than right.

Source
left <= right

Left less than or equal to right.

Source
left <> right

Binary and string concatenation.

Source
left == right

Equality.

Source
left > right

Left greater than right.

Source
left >= right

Left greater than or equal to right.

Source
left and right

Boolean and.

Source
avg(numbers)

Aggregate function, averages the given field over the current group.

Source
binary(string)

Casts a binary literal to a binary type. By default a binary literal is of the string type.

Source
count(arg)

Aggregate function, counts the number of occurrences of the given field in the current group.

Source
date(datetime)

Extract date from datetime.

Source
datetime(date, time)

Create a datetime from a date and a time

Source
div(left, right)

Integer division.

Source
downcase(string)

Downcase string.

Source
field(var, atom)

References a field. This can be used when a field needs to be dynamically referenced.

Examples

x = :title
from(p in Post, select: field(p, ^x))
Source
ilike(left, right)

Case-insensitive pattern match.

Source
left in right

Return true if left is in right array, false otherwise.

Source
is_nil(arg)

Returns true if argument is nil.

Source
like(left, right)

Case-sensitive pattern match.

Source
localtimestamp()

Returns the current local date and time.

Source
max(numbers)

Aggregate function, the maximum number of the given field in the current group.

Source
min(numbers)

Aggregate function, the minimum number of the given field in the current group.

Source
not arg

Boolean not.

Source
now()

Returns the current date and time.

Source
left or right

Boolean or.

Source
pow(base, exp)

base to the power of exp.

Source
random()

Random float number from 0.0 to 1.0 including.

Source
rem(left, right)

Integer remainder of division.

Source
round(number)

Round number to closest integer.

Source
round(x0, x1)
Source
sum(numbers)

Aggregate function, sums the given field over the current group.

Source
time(datetime)

Extract time from datetime.

Source
time_add(left, right)

Addition of datetime’s with interval’s

Source
time_sub(left, right)

Subtraction of datetime’s with interval’s

Source
upcase(string)

Upcase string.

Source
uuid(string)

Casts a binary literal to a uuid type. By default a binary literal is of the string type.

Source