general-syntax-table.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!--
  2. To render properly, keep the left-hand alignment.
  3. -->
  4. <table>
  5. <thead>
  6. <tr>
  7. <th></th>
  8. <th>Idiomatic Materialize SQL Pattern</th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. <tr>
  13. <td><code>ANY()</code> Equi-join condition</td>
  14. <td class="copyableCode">
  15. ***If no duplicates in the unnested field***
  16. ```mzsql
  17. WITH my_expanded_values AS
  18. (SELECT UNNEST(array|list|map) AS fieldZ FROM tableB)
  19. SELECT a.fieldA, ...
  20. FROM tableA a
  21. JOIN my_expanded_values t ON a.fieldZ = t.fieldZ
  22. ;
  23. ```
  24. ***If duplicates exist in the unnested field***
  25. ```mzsql
  26. WITH my_expanded_values AS
  27. (SELECT DISTINCT UNNEST(array|list|map) AS fieldZ FROM tableB)
  28. SELECT a.fieldA, ...
  29. FROM tableA a
  30. JOIN my_expanded_values t ON a.fieldZ = t.fieldZ
  31. ;
  32. ```
  33. </td>
  34. </tr>
  35. <tr>
  36. <td><code>mz_now()</code> cannot be used with date/time operators</td>
  37. <td>
  38. Rewrite the query expression; specifically, move the operation to the other side of the comparison.
  39. </td>
  40. </tr>
  41. <tr>
  42. <td><code>mz_now()</code> cannot be used with <code>OR</code>s in materialized/indexed view definitions and <code>SUBSCRIBE</code> statements</td>
  43. <td>
  44. Rewrite as <code>UNION ALL</code> or <code>UNION</code>, deduplicating as
  45. necessary:
  46. <ul>
  47. <li>In some cases, you may need to modify the conditions to deduplicate results
  48. when using <code>UNION ALL</code>. For example, you might add the negation of
  49. one input's condition to the other as a conjunction.</li>
  50. <li>In some cases, using <code>UNION</code> instead of <code>UNION ALL</code>
  51. may suffice if the inputs do not contain other duplicates that need to be
  52. retained.</li>
  53. </ul>
  54. </td>
  55. </tr>
  56. </tbody>
  57. </table>