DBToaster
DBToaster StdLib Reference

DBToaster includes a standard library of functions that may used in SQL queries. Functions are called using a C-like syntax:

SELECT listmin(A, B) FROM R;
See DBToaster SQL Reference for information about calling functions.


1. listmin, listmax

Compute the minimum or maximum of a fixed-size list of values.
listmin (val1, val2, [val3, [val4, [...]]]) listmax (val1, val2, [val3, [val4, [...]]])

Inputs

val1, val2, ...: any
An arbitrary number of value expressions. All values in the list must be of the same type, or escalateable to the same type (e.g., Int -> Float), and must be comparable.

Output

Returns the minimum or maximum element of val1, val2, .... The return type is the type of all of the elements of the list.

Notes

This library function is supported on the Interpreter, C++, and Scala runtimes.

2. date_part

Extract the parts of a date. Identical to EXTRACT(datepart FROM date).
date_part ('year', date) date_part ('month', date) date_part ('day', date)

Inputs

datepart: string literal
One of the string literals 'year', 'month', or 'day'. Dictates which part of the date to extract. datepart is case-insensitive.
date: date
The day to extract a component of.

Output

Returns the requested year, month, or date part of a date, as an integer.

Notes

This library function is supported on the Interpreter and C++ runtimes.

3. regexp_match

Perform regular expression matching.
regexp_match (pattern, string)

Inputs

pattern: string
A regular expression pattern (see Notes below).
string: string
The string to match against.

Output

Returns the integer 1 if the match succeeds, and the integer 0 otherwise.

Notes

This library function is supported on the Interpreter and C++ runtimes.

Note: Regular expressions are compiled and evaluated using each target runtime's native regular expression library. The Interpreter uses Ocaml's built in Str module. The C++ code generator uses regex(3).


4. substring

Extract a substring.
substring (string, start, len)

Inputs

string: string
The string to extract a substring from.
start: int
The first character of string to return. 0 is the first character of the string.
len: int
The length of the substring to return.

Output

Returns the substring of string of length len, starting at index start.

Notes

This library function is supported on the Interpreter and C++ runtimes.


5. cast_int,cast_float,cast_string,cast_date

Typecasting operations.
cast_int(val) cast_float(val) cast_string(val) cast_date(val)

Inputs

val: any
The value to cast. The value's type must be one that is castable to the target type.

Output

Returns the cast value of val as follows. If val is already of the target type, it is passed through unchanged.
FromToNotes
intfloat The floating point representation of the input.
intstring The string representation of the input, as determined by the runtime's standard stringification functionality.
floatint The integer representation of the input. Non-integer values will be truncated.
floatstring The string representation of the input, as determined by the runtime's standard stringification functionality.
datestring The string representation of the input, in the SQL-standard YYYY-MM-DD date format.
stringint The input parsed as an integer, using the runtime's standard integer parsing functionality.
(Ocaml: int_of_string, C++: atoi(3))
stringfloat The input parsed as a float, using the runtime's standard integer parsing functionality.
(Ocaml: float_of_string, C++: atof(3))
stringdate The input parsed as a date. The input string must be in SQL-standard YYYY-MM-DD date format, or a runtime error will be generated.

Notes

This library function is supported on the Interpreter and C++ runtimes.