substring.asciidoc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [discrete]
  2. [[esql-substring]]
  3. === `SUBSTRING`
  4. *Syntax*
  5. [.text-center]
  6. image::esql/functions/signature/substring.svg[Embedded,opts=inline]
  7. *Parameters*
  8. `str`::
  9. String expression. If `null`, the function returns `null`.
  10. `start`::
  11. Start position.
  12. `length`::
  13. Length of the substring from the start position. Optional; if omitted, all
  14. positions after `start` are returned.
  15. *Description*
  16. Returns a substring of a string, specified by a start position and an optional
  17. length.
  18. include::types/substring.asciidoc[]
  19. *Examples*
  20. This example returns the first three characters of every last name:
  21. [source.merge.styled,esql]
  22. ----
  23. include::{esql-specs}/docs.csv-spec[tag=substring]
  24. ----
  25. [%header.monospaced.styled,format=dsv,separator=|]
  26. |===
  27. include::{esql-specs}/docs.csv-spec[tag=substring-result]
  28. |===
  29. A negative start position is interpreted as being relative to the end of the
  30. string. This example returns the last three characters of of every last name:
  31. [source.merge.styled,esql]
  32. ----
  33. include::{esql-specs}/docs.csv-spec[tag=substringEnd]
  34. ----
  35. [%header.monospaced.styled,format=dsv,separator=|]
  36. |===
  37. include::{esql-specs}/docs.csv-spec[tag=substringEnd-result]
  38. |===
  39. If length is omitted, substring returns the remainder of the string. This
  40. example returns all characters except for the first:
  41. [source.merge.styled,esql]
  42. ----
  43. include::{esql-specs}/docs.csv-spec[tag=substringRemainder]
  44. ----
  45. [%header.monospaced.styled,format=dsv,separator=|]
  46. |===
  47. include::{esql-specs}/docs.csv-spec[tag=substringRemainder-result]
  48. |===