1
0

substring.asciidoc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. *Supported types*
  19. include::types/substring.asciidoc[]
  20. *Examples*
  21. This example returns the first three characters of every last name:
  22. [source.merge.styled,esql]
  23. ----
  24. include::{esql-specs}/docs.csv-spec[tag=substring]
  25. ----
  26. [%header.monospaced.styled,format=dsv,separator=|]
  27. |===
  28. include::{esql-specs}/docs.csv-spec[tag=substring-result]
  29. |===
  30. A negative start position is interpreted as being relative to the end of the
  31. string. This example returns the last three characters of of every last name:
  32. [source.merge.styled,esql]
  33. ----
  34. include::{esql-specs}/docs.csv-spec[tag=substringEnd]
  35. ----
  36. [%header.monospaced.styled,format=dsv,separator=|]
  37. |===
  38. include::{esql-specs}/docs.csv-spec[tag=substringEnd-result]
  39. |===
  40. If length is omitted, substring returns the remainder of the string. This
  41. example returns all characters except for the first:
  42. [source.merge.styled,esql]
  43. ----
  44. include::{esql-specs}/docs.csv-spec[tag=substringRemainder]
  45. ----
  46. [%header.monospaced.styled,format=dsv,separator=|]
  47. |===
  48. include::{esql-specs}/docs.csv-spec[tag=substringRemainder-result]
  49. |===