sql-cli 1.68.0

SQL query tool for CSV/JSON with both interactive TUI and non-interactive CLI modes - perfect for exploration and automation
Documentation
# SQL Functions Implementation Status

## ✅ Implemented Functions

### Mathematical Functions (Completed)
- `ABS(value)` - Absolute value
-`CEIL/CEILING(value)` - Round up
-`FLOOR(value)` - Round down
-`ROUND(value, decimals)` - Round to N decimal places
-`POW/POWER(base, exponent)` - Power
-`SQRT(value)` - Square root
-`MOD(a, b)` - Modulo operation
-`EXP(value)` - Exponential function
-`LN(value)` - Natural logarithm
-`LOG(value)` - Base-10 logarithm
-`LOG2(value)` - Base-2 logarithm
-`PI()` - Returns π
-`RANDOM()` - Random number
-`SIGN(value)` - Sign of number
-`TRUNC(value, decimals)` - Truncate

### Trigonometric Functions (Completed)
- `SIN(value)` - Sine
-`COS(value)` - Cosine
-`TAN(value)` - Tangent
-`ASIN(value)` - Arcsine
-`ACOS(value)` - Arccosine
-`ATAN(value)` - Arctangent
-`ATAN2(y, x)` - Two-argument arctangent
-`DEGREES(radians)` - Convert radians to degrees
-`RADIANS(degrees)` - Convert degrees to radians

### String Functions (Partially Completed)
- `LENGTH(string)` - String length
-`UPPER(string)` - Convert to uppercase
-`LOWER(string)` - Convert to lowercase
-`TRIM(string)` - Remove leading/trailing spaces
-`LTRIM(string)` - Remove leading spaces
-`RTRIM(string)` - Remove trailing spaces
-`REPLACE(string, old, new)` - Replace substring
-`SUBSTRING(string, start, length)` - Extract substring
-`SUBSTRING_AFTER(string, delimiter, occurrence)` - Extract after delimiter
-`CONTAINS(string, substring)` - Check if contains
-`CONCAT(string1, string2)` - Concatenate strings
-`ASCII(char)` - ASCII code of character
-`CHR(code)` - Character from ASCII code
-`CLEAN_TEXT(string)` - Normalize whitespace
-`CENTER(string, width)` - Center string
-`LJUST(string, width)` - Left justify
-`RJUST(string, width)` - Right justify
-`REPEAT(string, count)` - Repeat string

### Date Functions (Partially Completed)
- `NOW()` - Current timestamp
-`TODAY()` - Current date
-`YEAR(date)` - Extract year
-`MONTH(date)` - Extract month
-`DAY(date)` - Extract day
-`HOUR(time)` - Extract hour
-`MINUTE(time)` - Extract minute
-`SECOND(time)` - Extract second
-`DATEADD(unit, amount, date)` - Add to date
-`DATEDIFF(unit, date1, date2)` - Date difference

### Aggregate Functions (Partially Completed)
- `COUNT(*)` - Count rows
-`SUM(column)` - Sum values
-`AVG(column)` - Average
-`MIN(column)` - Minimum
-`MAX(column)` - Maximum
-`MEDIAN(column)` - Median value
-`MODE(column)` - Most frequent value (numeric only)
-`STDDEV(column)` - Standard deviation (population)
-`STDDEV_SAMP(column)` - Sample standard deviation
-`VARIANCE(column)` - Variance (population)
-`VAR_SAMP(column)` - Sample variance
-`PERCENTILE(column)` - 50th percentile by default
-`CORR(col1, col2)` - Correlation coefficient

### Type Checking Functions (Completed)
- `IS_DATE(value)` - Check if value is a date
-`IS_NUMERIC(value)` - Check if numeric
-`IS_FLOAT(value)` - Check if float
-`IS_INTEGER(value)` - Check if integer
-`IS_BOOL(value)` - Check if boolean

### Conversion Functions (Completed)
- `CONVERT(value, from_unit, to_unit)` - Unit conversion
-`TO_BOOL(value)` - Convert to boolean
-`TO_INT(value)` - Convert to integer
-`TO_FLOAT(value)` - Convert to float
-`FORMAT_NUMBER(value, decimals, separator, grouping)` - Format number

### Special Domain Functions (Completed)
- ✅ Astronomical functions (masses, distances, radii of planets)
- ✅ Chemical functions (atomic mass, electron configuration)
- ✅ Physics constants (speed of light, Planck constant)
- ✅ Financial functions (PMT, PV, FV, RATE, NPV, IRR)

## 🔨 Functions to Implement (Priority Order)

### Phase 1: Critical Missing Functions (High Priority)

#### String Functions
1. **`INSTR(string, substring)`** - Find position of substring
2. **`LEFT(string, n)`** - Get first N characters
3. **`RIGHT(string, n)`** - Get last N characters
4. **`REVERSE(string)`** - Reverse string
5. **`LPAD(string, length, pad)`** - Left pad string
6. **`RPAD(string, length, pad)`** - Right pad string
7. **`INITCAP(string)`** - Capitalize first letter of each word
8. **`SOUNDEX(string)`** - Phonetic encoding for fuzzy matching
9. **`LEVENSHTEIN(str1, str2)`** - Edit distance between strings
10. **`SPLIT(string, delimiter)`** - Split string into array

#### Date/Time Functions
1. **`WEEKDAY(date)`** - Day of week (0-6)
2. **`DAYNAME(date)`** - Name of weekday
3. **`MONTHNAME(date)`** - Name of month
4. **`QUARTER(date)`** - Quarter (1-4)
5. **`WEEK(date)`** - Week of year
6. **`DAYOFYEAR(date)`** - Day of year (1-366)
7. **`LAST_DAY(date)`** - Last day of month
8. **`DATE_FORMAT(date, format)`** - Format date as string
9. **`TIME_FORMAT(time, format)`** - Format time as string
10. **`UNIX_TIMESTAMP(date)`** - Convert to Unix timestamp
11. **`FROM_UNIXTIME(timestamp)`** - Convert from Unix timestamp

#### Array/List Functions (New Category)
1. **`ARRAY_LENGTH(array)`** - Length of array
2. **`ARRAY_CONTAINS(array, value)`** - Check if array contains value
3. **`ARRAY_MIN(array)`** - Minimum value in array
4. **`ARRAY_MAX(array)`** - Maximum value in array
5. **`ARRAY_SUM(array)`** - Sum of array values
6. **`ARRAY_AVG(array)`** - Average of array values
7. **`ARRAY_DISTINCT(array)`** - Unique values in array
8. **`ARRAY_SORT(array)`** - Sort array
9. **`ARRAY_REVERSE(array)`** - Reverse array
10. **`ARRAY_JOIN(array, delimiter)`** - Join array to string

### Phase 2: Statistical/Analytical Functions (Medium Priority)

1. **`PERCENTILE_CONT(column, percentile)`** - Continuous percentile
2. **`PERCENTILE_DISC(column, percentile)`** - Discrete percentile
3. **`QUARTILE(column, n)`** - Nth quartile (1-3)
4. **`IQR(column)`** - Interquartile range
5. **`MAD(column)`** - Median absolute deviation
6. **`SKEWNESS(column)`** - Measure of asymmetry
7. **`COVAR_POP(col1, col2)`** - Population covariance
8. **`COVAR_SAMP(col1, col2)`** - Sample covariance
9. **`REGR_SLOPE(y, x)`** - Regression slope
10. **`REGR_INTERCEPT(y, x)`** - Regression intercept
11. **`REGR_R2(y, x)`** - R-squared value

### Phase 3: Advanced Mathematical Functions (Lower Priority)

1. **`FACTORIAL(n)`** - Factorial
2. **`GCD(a, b)`** - Greatest common divisor
3. **`LCM(a, b)`** - Least common multiple
4. **`HYPOT(x, y)`** - Hypotenuse sqrt(x²+y²)
5. **`CBRT(value)`** - Cube root
6. **`SINH(value)`** - Hyperbolic sine
7. **`COSH(value)`** - Hyperbolic cosine
8. **`TANH(value)`** - Hyperbolic tangent
9. **`ERF(value)`** - Error function
10. **`GAMMA(value)`** - Gamma function

### Phase 4: Business/Financial Functions (Lower Priority)

1. **`DAYS360(start, end)`** - Days between dates (360-day year)
2. **`YEARFRAC(start, end)`** - Fraction of year between dates
3. **`WORKDAY(start, days)`** - Add working days
4. **`NETWORKDAYS(start, end)`** - Working days between dates
5. **`XIRR(values, dates)`** - Internal rate of return for irregular periods
6. **`XNPV(rate, values, dates)`** - NPV for irregular periods

### Phase 5: Utility Functions (Nice to Have)

1. **`COALESCE(val1, val2, ...)`** - First non-NULL value
2. **`NULLIF(val1, val2)`** - NULL if values equal
3. **`NVL(value, default)`** - Replace NULL with default
4. **`DECODE(value, search1, result1, ...)`** - Simple case logic
5. **`HASH(value, algorithm)`** - Hash value (MD5, SHA1, SHA256)
6. **`ENCODE(string, format)`** - Encode string (base64, hex)
7. **`DECODE(string, format)`** - Decode string
8. **`UUID()`** - Generate UUID
9. **`SLEEP(seconds)`** - Pause execution

## Implementation Strategy

### Quick Wins (1-2 days each)
- String position functions (INSTR, LEFT, RIGHT)
- String padding (LPAD, RPAD)
- Date extraction (WEEKDAY, QUARTER, WEEK)
- Array basics (LENGTH, CONTAINS, MIN, MAX)

### Medium Effort (3-5 days each)
- Statistical functions (PERCENTILE_CONT, IQR, MAD)
- Date formatting (DATE_FORMAT, TIME_FORMAT)
- String distance (LEVENSHTEIN, SOUNDEX)
- Array operations (SORT, DISTINCT, JOIN)

### Complex Implementation (1 week+)
- Regression functions (REGR_SLOPE, REGR_R2)
- Working day calculations (WORKDAY, NETWORKDAYS)
- Advanced financial (XIRR, XNPV)

## Notes

- MODE currently only works on numeric columns - consider extending to text
- Consider adding GREATEST/LEAST for multiple arguments
- Window functions (ROW_NUMBER, RANK, DENSE_RANK) would be valuable but require significant parser changes
- Consider supporting user-defined functions (UDFs) in future