Skip to content

Conversation

@slabko
Copy link
Contributor

@slabko slabko commented Jan 9, 2026

  • Return an error for any {fn ...} sequence that cannot be parsed or contain unknown scalar function, instead of trying to feed the query to ClickHouse

String

  • ASCII( string_exp ) 
  • BIT_LENGTH( string_exp ) 
  • CHAR( code ) 
  • CHAR_LENGTH( string_exp ) 
  • CHARACTER_LENGTH( string_exp ) 
  • CONCAT( string_exp1,string_exp2) 
  • DIFFERENCE( string_exp1,string_exp2)
  • INSERT( string_exp1, start, length, string_exp2) 
  • LCASE( string_exp ) 
  • LEFT( string_exp, count) 
  • LENGTH( string_exp ) 
  • LOCATE( string_exp1, string_exp2[, start]) 
  • LTRIM( string_exp ) 
  • OCTET_LENGTH( string_exp ) 
  • POSITION( character_exp IN character_exp) 
  • REPEAT( string_exp, count) 
  • REPLACE( string_exp1, string_exp2, string_exp3) 
  • RIGHT( string_exp, count) 
  • RTRIM( string_exp ) 
  • SOUNDEX( string_exp ) 
  • SPACE( count ) 
  • SUBSTRING( string_exp, start, length**)**
  • UCASE( string_exp ) 

Numeric

  • ABS( numeric_exp ) 
  • ACOS( float_exp ) 
  • ASIN( float_exp ) 
  • ATAN( float_exp ) 
  • ATAN2( float_exp1, float_exp2) 
  • CEILING( numeric_exp ) 
  • COS( float_exp ) 
  • COT( float_exp ) 
  • DEGREES( numeric_exp ) 
  • EXP( float_exp ) 
  • FLOOR( numeric_exp ) 
  • LOG( float_exp ) 
  • LOG10( float_exp ) 
  • MOD( integer_exp1, integer_exp2) 
  • PI( ) 
  • POWER( numeric_exp, integer_exp) 
  • RADIANS( numeric_exp ) 
  • RAND([integer_exp]) 
    • Implement multiple RAND calls in the same query
    • Implement multiple RAND calls in the same query
  • ROUND( numeric_exp, integer_exp) 
  • SIGN( numeric_exp ) 
  • SIN( float_exp ) 
  • SQRT( float_exp ) 
  • TAN( float_exp ) 
  • TRUNCATE( numeric_exp, integer_exp) 

Date/Time

Some of these functions has already been implemented but miss testing/review

  • CURRENT_DATE( ) 
  • CURRENT_TIME[( time-precision )] 
  • CURRENT_TIMESTAMP [( timestamp-precision )] 
  • CURDATE( ) 
  • CURTIME( ) 
  • DAYNAME( date_exp ) 
  • DAYOFMONTH( date_exp ) 
  • DAYOFWEEK( date_exp ) 
  • DAYOFYEAR( date_exp ) 
  • EXTRACT( extract-field FROM extract-source ) 
  • HOUR( time_exp ) 
  • MINUTE( time_exp ) 
  • MONTH( date_exp ) 
  • MONTHNAME( date_exp ) 
  • NOW( ) 
  • QUARTER( date_exp ) 
  • SECOND( time_exp ) 
  • TIMESTAMPADD( interval, integer_exp, timestamp_exp ) 
  • TIMESTAMPDIFF( interval, timestamp_exp1, timestamp_exp2 ) 
  • WEEK( date_exp ) 
  • YEAR( date_exp ) 

System

Some of these functions has already been implemented but miss testing/review

  • DATABASE( ) 
  • IFNULL( exp, value ) 
  • USER( ) 

Conversion

The function has already been implemented but misses testing/review

  • CONVERT( value, type )

@slabko slabko force-pushed the scalar-functions branch 2 times, most recently from f82bc3d to 9929001 Compare January 9, 2026 19:23
slabko added 3 commits January 9, 2026 20:57
Scalar functions are declared in the same namespace (enum) as other
tokens, such as COMMA, SPACE, LPARENT, etc. This makes scalar function
names conflict with token names. For example, there is a SPACE token
and a SPACE scalar function. To avoid naming conflicts, all scalar
functions now have an FN_ prefix.
@slabko
Copy link
Contributor Author

slabko commented Jan 9, 2026

There seem to be a problem in our staging Cloud environment, it mixes positions of haystack and needle. This should return 7, but it returns 0:

SELECT locate('World', 'Hello World')

However for this it returns 7, but should return 0 (according to the documentation and all other non-staging instances)

SELECT locate('Hello World', 'World')

The order of parameters in `locate` can be configured, which might cause
problems in environments with non-default settings. `position` always
work the same in that sense.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants