conditional.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. ----
  54. [[sql-functions-conditional-isnull]]
  55. ==== `ISNULL`
  56. .Synopsis
  57. [source, sql]
  58. ----
  59. ISNULL ( expression<1>, expression<2> )
  60. ----
  61. *Input*:
  62. <1> 1st expression
  63. <2> 2nd expression
  64. *Output*: 2nd expression if 1st expression is null, otherwise 1st expression.
  65. .Description
  66. Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
  67. Returns the first of its arguments that is not null.
  68. If all arguments are null, then it returns `null`.
  69. ["source","sql",subs="attributes,callouts,macros"]
  70. ----
  71. include-tagged::{sql-specs}/docs.csv-spec[isNullReturnFirst]
  72. ----
  73. ["source","sql",subs="attributes,callouts,macros"]
  74. ----
  75. include-tagged::{sql-specs}/docs.csv-spec[isNullReturnSecond]
  76. ----