scalar-func-table-position.slt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. # Selecting from scalar functions in FROM clauses
  10. query I
  11. SELECT length FROM length('str');
  12. ----
  13. 3
  14. query I
  15. SELECT * FROM length('str');
  16. ----
  17. 3
  18. query T
  19. SELECT * FROM repeat('x', 2);
  20. ----
  21. xx
  22. query T
  23. SELECT repeat FROM repeat('x', 2);
  24. ----
  25. xx
  26. query T
  27. SELECT * FROM concat('a','b','c');
  28. ----
  29. abc
  30. query T
  31. SELECT concat FROM concat('a','b','c');
  32. ----
  33. abc
  34. # Passes through decorrelation
  35. query I
  36. SELECT lat_len FROM length('abc'), LATERAL (SELECT length AS lat_len) lat;
  37. ----
  38. 3
  39. # Aliases
  40. query I colnames
  41. SELECT * FROM length('str');
  42. ----
  43. length
  44. 3
  45. query I colnames
  46. SELECT * FROM length('str') AS x;
  47. ----
  48. x
  49. 3
  50. query I colnames
  51. SELECT * FROM length('str') AS x(a);
  52. ----
  53. a
  54. 3
  55. # Ordinality
  56. query II colnames
  57. SELECT * FROM length('str') WITH ORDINALITY;
  58. ----
  59. length ordinality
  60. 3
  61. 1
  62. # Aliases + ordinality
  63. query II colnames
  64. SELECT * FROM length('str') AS x WITH ORDINALITY;
  65. ----
  66. x ordinality
  67. 3
  68. 1
  69. query II colnames
  70. SELECT * FROM length('str') AS x(a) WITH ORDINALITY;
  71. ----
  72. a ordinality
  73. 3
  74. 1
  75. # Nested recursion.
  76. query I
  77. SELECT length FROM length('str' || (select length FROM length('str')));
  78. ----
  79. 4
  80. # Cross-joined
  81. query T
  82. SELECT concat_ws(' ', l, a, b) FROM length('str') AS l, (values ('a', 'b'), ('c', 'd')) v(a,b);
  83. ----
  84. 3 a b
  85. 3 c d
  86. # Test functions that exist as catalog-only
  87. query I
  88. SELECT mod FROM mod(3,4);
  89. ----
  90. 3
  91. query I
  92. SELECT * FROM mod(3,4);
  93. ----
  94. 3
  95. # Nested recursion.
  96. query I
  97. SELECT mod FROM mod((SELECT mod FROM mod(3,4)),4);
  98. ----
  99. 3
  100. # Passes through decorrelation
  101. query I
  102. SELECT lat_mod FROM mod(3,4), LATERAL (SELECT mod AS lat_mod) lat;
  103. ----
  104. 3
  105. # Aliases
  106. query I colnames
  107. SELECT x FROM mod(3,4) AS x;
  108. ----
  109. x
  110. 3
  111. query I colnames
  112. SELECT a FROM mod(3,4) AS x(a);
  113. ----
  114. a
  115. 3
  116. # Ordinality
  117. query II colnames
  118. SELECT * FROM mod(3,4) WITH ORDINALITY;
  119. ----
  120. mod ordinality
  121. 3
  122. 1
  123. # Aliases + ordinality
  124. query II colnames
  125. SELECT * FROM mod(3,4) AS x WITH ORDINALITY;
  126. ----
  127. x ordinality
  128. 3
  129. 1
  130. query II colnames
  131. SELECT * FROM mod(3,4) AS x(a) WITH ORDINALITY;
  132. ----
  133. a ordinality
  134. 3
  135. 1
  136. # Aggregates
  137. query error db error: ERROR: aggregate functions are not supported in functions in FROM
  138. SELECT * FROM sum(4)
  139. query error db error: ERROR: aggregate functions are not supported in functions in FROM
  140. SELECT * FROM (VALUES (1), (3)) AS t(a), LATERAL(SELECT * FROM sum(a));
  141. # Aggregates that exist as catalog only
  142. query error db error: ERROR: aggregate functions are not supported in functions in FROM
  143. SELECT * FROM avg(4)
  144. query error db error: ERROR: aggregate functions are not supported in functions in FROM
  145. SELECT * FROM (VALUES (1), (3)) AS t(a), LATERAL(SELECT * FROM avg(a));