operator.slt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. statement OK
  10. CREATE TABLE tbl(string text);
  11. statement OK
  12. INSERT INTO tbl(string)
  13. SELECT x::text FROM generate_series(1, 10000) x;
  14. query I
  15. select 2 OPERATOR(*) 2;
  16. ----
  17. 4
  18. query I
  19. select 2 OPERATOR(+) 2;
  20. ----
  21. 4
  22. query I
  23. select 2 OPERATOR(-) 2;
  24. ----
  25. 0
  26. query I
  27. select 2 OPERATOR(/) 2
  28. ----
  29. 1
  30. query I
  31. select 2 OPERATOR(pg_catalog.*) 2;
  32. ----
  33. 4
  34. query I
  35. select 2 OPERATOR(pg_catalog.+) 2;
  36. ----
  37. 4
  38. query I
  39. select 2 OPERATOR(pg_catalog.-) 2;
  40. ----
  41. 0
  42. query I
  43. select 2 OPERATOR(pg_catalog./) 2
  44. ----
  45. 1
  46. query error operator does not exist: mz_catalog.*
  47. select 2 OPERATOR(mz_catalog.*) 2;
  48. query error operator does not exist: mz_catalog.public.*
  49. select 2 OPERATOR(mz_catalog.public.*) 2;
  50. query error Expected operator, found number "5."
  51. select 2 OPERATOR(5.*) 2;
  52. # confirm the precedence of the OPERATOR
  53. query I
  54. select 2 OPERATOR(*) 2 + 2;
  55. ----
  56. 8
  57. query I
  58. select 2 OPERATOR(*) 2 OPERATOR(+) 2;
  59. ----
  60. 6
  61. query I
  62. select 2 * 2 OPERATOR(+) 2;
  63. ----
  64. 6
  65. query T
  66. SELECT * FROM tbl WHERE string ~ '^1234'
  67. ----
  68. 1234
  69. query T
  70. SELECT * FROM tbl WHERE string OPERATOR(~) '^1234'
  71. ----
  72. 1234
  73. query T
  74. SELECT * FROM tbl WHERE string OPERATOR(pg_catalog.~) '^1234'
  75. ----
  76. 1234
  77. query T
  78. SELECT * FROM tbl WHERE string ~ '^123$'
  79. ----
  80. 123
  81. query T
  82. SELECT * FROM tbl WHERE string OPERATOR(~) '^123$'
  83. ----
  84. 123
  85. query T
  86. SELECT * FROM tbl WHERE string OPERATOR(pg_catalog.~) '^123$'
  87. ----
  88. 123
  89. # Confirm that operators can be used in views
  90. statement ok
  91. CREATE VIEW PG_ADDER AS SELECT 2 OPERATOR(pg_catalog.+) 2;
  92. query TT
  93. SHOW CREATE VIEW PG_ADDER
  94. ----
  95. materialize.public.pg_adder
  96. CREATE VIEW materialize.public.pg_adder AS SELECT 2 OPERATOR(pg_catalog.+) 2;
  97. statement ok
  98. CREATE VIEW ADDER AS SELECT 2 OPERATOR(+) 2;
  99. query TT
  100. SHOW CREATE VIEW ADDER
  101. ----
  102. materialize.public.adder
  103. CREATE VIEW materialize.public.adder AS SELECT 2 OPERATOR(+) 2;
  104. simple conn=mz_catalog_server,user=mz_support
  105. SHOW CREATE VIEW ADDER
  106. ----
  107. materialize.public.adder,CREATE VIEW materialize.public.adder AS SELECT 2 OPERATOR(+) 2;
  108. COMPLETE 1
  109. statement ok
  110. CREATE VIEW MULTIPLIER AS SELECT 2 OPERATOR(*) 2;
  111. query TT
  112. SHOW CREATE VIEW MULTIPLIER
  113. ----
  114. materialize.public.multiplier
  115. CREATE VIEW materialize.public.multiplier AS SELECT 2 OPERATOR(*) 2;
  116. statement ok
  117. CREATE VIEW PG_MULTIPLIER AS SELECT 2 OPERATOR(pg_catalog.*) 2;
  118. query TT
  119. SHOW CREATE VIEW PG_MULTIPLIER
  120. ----
  121. materialize.public.pg_multiplier
  122. CREATE VIEW materialize.public.pg_multiplier AS SELECT 2 OPERATOR(pg_catalog.*) 2;
  123. query error Expected operator, found number "5."
  124. CREATE VIEW INVALID_FIVE AS select 2 OPERATOR(5.*) 2;
  125. query II
  126. SELECT 2 OPERATOR(*) 2 + 2, 2 * 2 + 2
  127. ----
  128. 8
  129. 6