func Module

Attention

Hashquery is currently in public preview. Here are some caveats to keep in mind for early adopters:

  • Backwards compatibility may not be preserved between version upgrades, and you may need to update your package regularly.

  • There may be differences in the SQL logic generated by hashquery compared to the Hashboard app.

  • You may encounter dialect-specific SQL syntax errors or other unexpected errors. If you come across one, let us know by reporting an issue.

All the following are valid ways to reference these functions:

# import *
from hashquery import *
func.count()

# import func
from hashquery import func
func.count()

# direct named import
from hashquery.func import count
count()
cases(
*cases: Tuple[ColumnExpression, ColumnExpression | Any],
other: ColumnExpression | Any | None = None,
) ColumnExpression

Constructs a ColumnExpression that represents a SQL CASE expression.

Parameters:
  • *cases – List of (condition, value) pairs, where condition and value are ColumnExpressions.

  • other – The value (or expression) to use if none of the cases match. Defaults to None.

and_(
*clauses: ColumnExpression,
) ColumnExpression

an AND expression in SQL

or_(
*clauses: ColumnExpression,
) ColumnExpression

an OR expression in SQL

not_(
clause: ColumnExpression,
) ColumnExpression

a NOT expression in SQL

count(
target: ColumnExpression | None = None,
) ColumnExpression

an aggregating COUNT expression over the provided column or value. You can omit a value to form COUNT(*).

count_if(
condition: ColumnExpression,
) ColumnExpression

an aggregating expression which counts the records for which condition is True. Equivalent to SUM(CASE WHEN condition THEN 1 ELSE 0 END).

distinct(
target: ColumnExpression,
) ColumnExpression

an aggregating DISTINCT expression over the provided column.

max(
target: ColumnExpression,
) ColumnExpression

an aggregating MAX expression over the provided column.

min(
target: ColumnExpression,
) ColumnExpression

an aggregating MIN expression over the provided column.

sum(
target: ColumnExpression,
) ColumnExpression

an aggregating AVG expression over the provided column.

avg(
target: ColumnExpression,
) ColumnExpression

an aggregating AVG expression over the provided column.

floor(
target: ColumnExpression,
) ColumnExpression

a FLOOR expression over the provided column.

ceiling(
target: ColumnExpression,
) ColumnExpression

a CEILING expression over the provided column.

now() ColumnExpression

a NOW() expression in SQL, which will be evaluated at query-time. This is distinct from calling datetime.now, which would evaluate the expression at build-time.

exists(target: Model) ColumnExpression

an EXISTS function over a model.

diff_seconds(
ts1: ColumnExpression,
ts2: ColumnExpression,
) ColumnExpression

a diffSeconds expression over the provided timestamp columns. Returns the difference in seconds between the two timestamps.