conditional.asciidoc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-functions-conditional]]
  4. === Conditional Functions
  5. Functions that return one of their arguments by evaluating in an if-else manner.
  6. [[sql-functions-conditional-coalesce]]
  7. ==== `COALESCE`
  8. .Synopsis
  9. [source, sql]
  10. ----
  11. COALESCE ( expression<1>, expression<2>, ... )
  12. ----
  13. *Input*:
  14. <1> 1st expression
  15. <2> 2nd expression
  16. ...
  17. **N**th expression
  18. COALESCE can take an arbitrary number of arguments.
  19. *Output*: one of the expressions or `null`
  20. .Description
  21. Returns the first of its arguments that is not null.
  22. If all arguments are null, then it returns `null`.
  23. ["source","sql",subs="attributes,callouts,macros"]
  24. ----
  25. include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNonNull]
  26. ----
  27. ["source","sql",subs="attributes,callouts,macros"]
  28. ----
  29. include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNull]
  30. ----
  31. [[sql-functions-conditional-ifnull]]
  32. ==== `IFNULL`
  33. .Synopsis
  34. [source, sql]
  35. ----
  36. IFNULL ( expression<1>, expression<2> )
  37. ----
  38. *Input*:
  39. <1> 1st expression
  40. <2> 2nd expression
  41. *Output*: 2nd expression if 1st expression is null, otherwise 1st expression.
  42. .Description
  43. Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
  44. Returns the first of its arguments that is not null.
  45. If all arguments are null, then it returns `null`.
  46. ["source","sql",subs="attributes,callouts,macros"]
  47. ----
  48. include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnFirst]
  49. ----
  50. ["source","sql",subs="attributes,callouts,macros"]
  51. ----
  52. include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnSecond]
  53. ----