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.
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 |
is_nil(arg) | Returns |
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 |
Functions
Aggregate function, averages the given field over the current group.
Casts a binary literal to a binary type. By default a binary literal is of the string type.
Aggregate function, counts the number of occurrences of the given field in the current group.
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))
Aggregate function, the maximum number of the given field in the current group.
Aggregate function, the minimum number of the given field in the current group.