substring.asciidoc 781 B

12345678910111213141516171819202122232425262728293031
  1. [[esql-substring]]
  2. === `SUBSTRING`
  3. Returns a substring of a string, specified by a start position and an optional
  4. length. This example returns the first three characters of every last name:
  5. [source,esql]
  6. ----
  7. FROM employees
  8. | PROJECT last_name
  9. | EVAL ln_sub = SUBSTRING(last_name, 1, 3)
  10. ----
  11. A negative start position is interpreted as being relative to the end of the
  12. string. This example returns the last three characters of of every last name:
  13. [source,esql]
  14. ----
  15. FROM employees
  16. | PROJECT last_name
  17. | EVAL ln_sub = SUBSTRING(last_name, -3, 3)
  18. ----
  19. If length is omitted, substring returns the remainder of the string. This
  20. example returns all characters except for the first:
  21. [source,esql]
  22. ----
  23. FROM employees
  24. | PROJECT last_name
  25. | EVAL ln_sub = SUBSTRING(last_name, 2)
  26. ----