Selecto.SQL.Functions
(Selecto v0.4.5)
Copy Markdown
Advanced SQL function support for Selecto.
This module extends the existing function support in Selecto.Builder.Sql.Select with additional advanced SQL functions including window functions, array operations, string manipulation, and mathematical functions.
Function Categories
String Functions
substr/3- Extract substringtrim/1,ltrim/1,rtrim/1- String trimmingupper/1,lower/1- Case conversionlength/1- String lengthposition/2- Find substring positionreplace/3- String replacementsplit_part/3- Split and extract part
Mathematical Functions
abs/1- Absolute valueceil/1,floor/1- Rounding functionsround/1,round/2- Rounding with precisionpower/2- Exponentiationsqrt/1- Square rootmod/2- Modulo operationrandom/0- Random number generation
Date/Time Functions
now/0- Current timestampdate_trunc/2- Truncate to date partinterval/1- Time intervalsage/1,age/2- Date arithmeticdate_part/2- Enhanced extract functionality
Array Functions
array_agg/1- Array aggregationarray_length/1- Array lengtharray_to_string/2- Array to string conversionstring_to_array/2- String to array conversionunnest/1- Array expansionarray_cat/2- Array concatenation
Window Functions
row_number/0- Row numberingrank/0- Ranking with gapsdense_rank/0- Dense rankinglag/1,lag/2- Previous row valueslead/1,lead/2- Next row valuesfirst_value/1,last_value/1- Window boundariesntile/1- Percentile groups
Conditional Functions
- Enhanced
caseexpressions decode/3+- Oracle-style conditionaliif/3- Simple if-then-else
Usage Examples
# String functions
{:substr, "description", 1, 50}
{:trim, "name"}
{:upper, "category"}
# Math functions
{:round, "price", 2}
{:power, "base", 2}
# Window functions
{:window, {:row_number}, over: [partition_by: ["category"], order_by: ["price"]]}
{:window, {:lag, "price"}, over: [partition_by: ["product_id"], order_by: ["date"]]}
# Array functions
{:array_agg, "tag_name", over: [partition_by: ["product_id"]]}
{:unnest, "tags"}
Summary
Functions
Process advanced SQL functions that extend beyond the basic set.