Reference

SQL Functions

Common SQL string functions and operators available in ExoQuery

This section summarizes the most common string functions you can use directly inside captured SQL blocks. There are two sources of functions:

  • Kotlin String methods that are whitelisted by the compiler plugin (via MethodWhiteList) and translated by SqlIdiom
  • Additional helper methods available via the StringSqlDsl

Supported Kotlin String methods

Via MethodWhiteList:

  • substring(start, end) โ†’ SUBSTRING(column, start, end)
  • uppercase() โ†’ UPPER(column)
  • lowercase() โ†’ LOWER(column)
  • length โ†’ LENGTH/CHAR_LENGTH (dialect-dependent; may be rendered as LEN in some dialects)
  • trim() โ†’ TRIM(column)
    • Note: Only the zero-argument variation is supported. If you need to trim specific characters or trim only one side, use the StringSqlDsl helpers below.

StringSqlDsl helpers

You can call on string expressions inside a captured block:

  • left(n: Int) โ†’ LEFT(column, n)
  • right(n: Int) โ†’ RIGHT(column, n)
  • replace(old: String, new: String) โ†’ REPLACE(column, old, new)
  • substring(start: Int, end: Int) โ†’ SUBSTRING(column, start, end)

Note that all of these functions are being rendered into SQL by the ExoQuery SqlIdiom system so look at the generated SQL to see exactly what is being produced.