|
72 | 72 | [[ "$output" =~ "2.5" ]] || false |
73 | 73 | [[ "$output" =~ "b" ]] || false |
74 | 74 | } |
| 75 | + |
| 76 | +@test 'types: VALUES clause SUM with explicit cast' { |
| 77 | + run query_server -t -c "SELECT SUM(n::numeric) FROM (VALUES(1),(2.01),(3)) v(n);" |
| 78 | + [ "$status" -eq 0 ] |
| 79 | + [[ "$output" =~ "6.01" ]] || false |
| 80 | +} |
| 81 | + |
| 82 | +@test 'types: VALUES clause MIN and MAX with mixed types' { |
| 83 | + run query_server -t -c "SELECT MIN(n), MAX(n) FROM (VALUES(1),(2.5),(3),(0.5)) v(n);" |
| 84 | + [ "$status" -eq 0 ] |
| 85 | + [[ "$output" =~ "0.5" ]] || false |
| 86 | + [[ "$output" =~ "3" ]] || false |
| 87 | +} |
| 88 | + |
| 89 | +@test 'types: VALUES clause GROUP BY with mixed types' { |
| 90 | + run query_server -t -c "SELECT n, COUNT(*) FROM (VALUES(1),(2.5),(1),(3.5),(2.5)) v(n) GROUP BY n ORDER BY n;" |
| 91 | + [ "$status" -eq 0 ] |
| 92 | + [[ "$output" =~ "1" ]] || false |
| 93 | + [[ "$output" =~ "2.5" ]] || false |
| 94 | + [[ "$output" =~ "3.5" ]] || false |
| 95 | +} |
| 96 | + |
| 97 | +@test 'types: VALUES clause SUM GROUP BY with mixed types' { |
| 98 | + run query_server -t -c "SELECT category, SUM(amount) FROM (VALUES('a', 1),('b', 2.5),('a', 3),('b', 4.5)) v(category, amount) GROUP BY category ORDER BY category;" |
| 99 | + [ "$status" -eq 0 ] |
| 100 | + [[ "$output" =~ "a" ]] || false |
| 101 | + [[ "$output" =~ "4" ]] || false |
| 102 | + [[ "$output" =~ "b" ]] || false |
| 103 | + [[ "$output" =~ "7.0" ]] || false |
| 104 | +} |
| 105 | + |
| 106 | +@test 'types: VALUES clause DISTINCT with mixed types' { |
| 107 | + run query_server -t -c "SELECT DISTINCT n FROM (VALUES(1),(2.5),(1),(2.5),(3)) v(n) ORDER BY n;" |
| 108 | + [ "$status" -eq 0 ] |
| 109 | + [[ "$output" =~ "1" ]] || false |
| 110 | + [[ "$output" =~ "2.5" ]] || false |
| 111 | + [[ "$output" =~ "3" ]] || false |
| 112 | +} |
| 113 | + |
| 114 | +@test 'types: VALUES clause ORDER BY with mixed types' { |
| 115 | + run query_server -t -c "SELECT * FROM (VALUES(3),(1.5),(2),(4.5)) v(n) ORDER BY n;" |
| 116 | + [ "$status" -eq 0 ] |
| 117 | + [[ "$output" =~ "1.5" ]] || false |
| 118 | + [[ "$output" =~ "2" ]] || false |
| 119 | + [[ "$output" =~ "3" ]] || false |
| 120 | + [[ "$output" =~ "4.5" ]] || false |
| 121 | +} |
| 122 | + |
| 123 | +@test 'types: VALUES clause ORDER BY DESC with mixed types' { |
| 124 | + run query_server -t -c "SELECT * FROM (VALUES(3),(1.5),(2),(4.5)) v(n) ORDER BY n DESC;" |
| 125 | + [ "$status" -eq 0 ] |
| 126 | + [[ "$output" =~ "4.5" ]] || false |
| 127 | + [[ "$output" =~ "3" ]] || false |
| 128 | + [[ "$output" =~ "2" ]] || false |
| 129 | + [[ "$output" =~ "1.5" ]] || false |
| 130 | +} |
| 131 | + |
| 132 | +@test 'types: VALUES clause LIMIT with mixed types' { |
| 133 | + run query_server -t -c "SELECT * FROM (VALUES(1),(2.5),(3),(4.5),(5)) v(n) LIMIT 3;" |
| 134 | + [ "$status" -eq 0 ] |
| 135 | + [[ "$output" =~ "1" ]] || false |
| 136 | + [[ "$output" =~ "2.5" ]] || false |
| 137 | + [[ "$output" =~ "3" ]] || false |
| 138 | + ! [[ "$output" =~ "4.5" ]] || false |
| 139 | + ! [[ "$output" =~ " 5" ]] || false |
| 140 | +} |
| 141 | + |
| 142 | +@test 'types: VALUES clause WHERE filter with mixed types' { |
| 143 | + run query_server -t -c "SELECT * FROM (VALUES(1),(2.5),(3),(4.5),(5)) v(n) WHERE n > 2;" |
| 144 | + [ "$status" -eq 0 ] |
| 145 | + [[ "$output" =~ "2.5" ]] || false |
| 146 | + [[ "$output" =~ "3" ]] || false |
| 147 | + [[ "$output" =~ "4.5" ]] || false |
| 148 | + [[ "$output" =~ "5" ]] || false |
| 149 | +} |
| 150 | + |
| 151 | +@test 'types: VALUES clause with NULLs and mixed types' { |
| 152 | + run query_server -t -c "SELECT * FROM (VALUES(1),(NULL),(2.5)) v(n);" |
| 153 | + [ "$status" -eq 0 ] |
| 154 | + [[ "$output" =~ "1" ]] || false |
| 155 | + [[ "$output" =~ "2.5" ]] || false |
| 156 | +} |
| 157 | + |
| 158 | +@test 'types: VALUES clause all same type no cast needed' { |
| 159 | + run query_server -t -c "SELECT * FROM (VALUES(1),(2),(3)) v(n);" |
| 160 | + [ "$status" -eq 0 ] |
| 161 | + [[ "$output" =~ "1" ]] || false |
| 162 | + [[ "$output" =~ "2" ]] || false |
| 163 | + [[ "$output" =~ "3" ]] || false |
| 164 | +} |
| 165 | + |
| 166 | +@test 'types: VALUES clause all string literals' { |
| 167 | + run query_server -t -c "SELECT * FROM (VALUES('a'),('b'),('c')) v(n);" |
| 168 | + [ "$status" -eq 0 ] |
| 169 | + [[ "$output" =~ "a" ]] || false |
| 170 | + [[ "$output" =~ "b" ]] || false |
| 171 | + [[ "$output" =~ "c" ]] || false |
| 172 | +} |
| 173 | + |
| 174 | +@test 'types: VALUES clause string concatenation' { |
| 175 | + run query_server -t -c "SELECT n || '!' FROM (VALUES('hello'),('world')) v(n);" |
| 176 | + [ "$status" -eq 0 ] |
| 177 | + [[ "$output" =~ "hello!" ]] || false |
| 178 | + [[ "$output" =~ "world!" ]] || false |
| 179 | +} |
| 180 | + |
| 181 | +@test 'types: VALUES clause type mismatch bool and int errors' { |
| 182 | + run query_server -t -c "SELECT * FROM (VALUES(true),(1),(false)) v(n);" |
| 183 | + [ "$status" -ne 0 ] |
| 184 | + [[ "$output" =~ "cannot be matched" ]] || false |
| 185 | +} |
| 186 | + |
| 187 | +@test 'types: VALUES clause JOIN with same types' { |
| 188 | + run query_server -t -c "SELECT a.n, b.label FROM (VALUES(1),(2),(3)) a(n) JOIN (VALUES(1, 'one'),(2, 'two'),(3, 'three')) b(id, label) ON a.n = b.id;" |
| 189 | + [ "$status" -eq 0 ] |
| 190 | + [[ "$output" =~ "1" ]] || false |
| 191 | + [[ "$output" =~ "one" ]] || false |
| 192 | + [[ "$output" =~ "2" ]] || false |
| 193 | + [[ "$output" =~ "two" ]] || false |
| 194 | + [[ "$output" =~ "3" ]] || false |
| 195 | + [[ "$output" =~ "three" ]] || false |
| 196 | +} |
| 197 | + |
| 198 | +@test 'types: VALUES clause JOIN with mixed types' { |
| 199 | + run query_server -t -c "SELECT a.n, b.label FROM (VALUES(1),(2.5),(3)) a(n) JOIN (VALUES(1, 'one'),(3, 'three')) b(id, label) ON a.n = b.id;" |
| 200 | + [ "$status" -eq 0 ] |
| 201 | + [[ "$output" =~ "1" ]] || false |
| 202 | + [[ "$output" =~ "one" ]] || false |
| 203 | + [[ "$output" =~ "3" ]] || false |
| 204 | + [[ "$output" =~ "three" ]] || false |
| 205 | +} |
| 206 | + |
| 207 | +@test 'types: VALUES clause CTE with mixed types' { |
| 208 | + run query_server -t -c "WITH nums AS (SELECT * FROM (VALUES(1),(2.5),(3)) v(n)) SELECT * FROM nums;" |
| 209 | + [ "$status" -eq 0 ] |
| 210 | + [[ "$output" =~ "1" ]] || false |
| 211 | + [[ "$output" =~ "2.5" ]] || false |
| 212 | + [[ "$output" =~ "3" ]] || false |
| 213 | +} |
| 214 | + |
| 215 | +@test 'types: VALUES clause CTE SUM with mixed types' { |
| 216 | + run query_server -t -c "WITH nums AS (SELECT * FROM (VALUES(1),(2.5),(3)) v(n)) SELECT SUM(n) FROM nums;" |
| 217 | + [ "$status" -eq 0 ] |
| 218 | + [[ "$output" =~ "6.5" ]] || false |
| 219 | +} |
| 220 | + |
| 221 | +@test 'types: VALUES clause multi-column partial cast' { |
| 222 | + # Only second column needs cast, first stays int |
| 223 | + run query_server -t -c "SELECT * FROM (VALUES(1, 10),(2, 20.5),(3, 30)) v(a, b);" |
| 224 | + [ "$status" -eq 0 ] |
| 225 | + [[ "$output" =~ "1" ]] || false |
| 226 | + [[ "$output" =~ "10" ]] || false |
| 227 | + [[ "$output" =~ "2" ]] || false |
| 228 | + [[ "$output" =~ "20.5" ]] || false |
| 229 | + [[ "$output" =~ "3" ]] || false |
| 230 | + [[ "$output" =~ "30" ]] || false |
| 231 | +} |
| 232 | + |
| 233 | +@test 'types: VALUES clause combined GROUP BY ORDER BY LIMIT' { |
| 234 | + run query_server -t -c "SELECT n, COUNT(*) as cnt FROM (VALUES(1),(2.5),(1),(2.5),(3),(1)) v(n) GROUP BY n ORDER BY cnt DESC LIMIT 2;" |
| 235 | + [ "$status" -eq 0 ] |
| 236 | + [[ "$output" =~ "1" ]] || false |
| 237 | + [[ "$output" =~ "3" ]] || false |
| 238 | + [[ "$output" =~ "2.5" ]] || false |
| 239 | + [[ "$output" =~ "2" ]] || false |
| 240 | +} |
| 241 | + |
| 242 | +@test 'types: VALUES clause combined WHERE ORDER BY LIMIT' { |
| 243 | + run query_server -t -c "SELECT * FROM (VALUES(1),(2.5),(3),(4.5),(5)) v(n) WHERE n > 1 ORDER BY n DESC LIMIT 2;" |
| 244 | + [ "$status" -eq 0 ] |
| 245 | + [[ "$output" =~ "5" ]] || false |
| 246 | + [[ "$output" =~ "4.5" ]] || false |
| 247 | +} |
0 commit comments