Skip to content

Commit a107216

Browse files
test: add type inference test examples for MySQL
Add comprehensive test cases to validate expression type inference: - Simple division operations (a1 / 1024) - CAST with COALESCE combinations - Explicit CAST operations - Arithmetic operations (+, -, *, %) - COALESCE with inferred types These examples help verify that the type inference system correctly handles mathematical expressions and nullable columns.
1 parent 6ff8bbd commit a107216

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- name: ListTest :many
2+
SELECT
3+
(a1 / 1024) a1_float, (a2 / 1024) a2_float, a3
4+
FROM test;
5+
6+
-- name: ListTest2 :many
7+
SELECT
8+
COALESCE(CAST(a1 / 1024 AS FLOAT), 0) a1_float, COALESCE(CAST(a2 / 1024 AS FLOAT), 0) a2_float, a3
9+
FROM test;
10+
11+
-- name: ListTest3 :many
12+
SELECT
13+
CAST(a1 / 1024 AS FLOAT) a1_float, CAST(a2 / 1024 AS FLOAT) a2_float, a3
14+
FROM test;
15+
16+
-- name: ListTest4 :many
17+
SELECT
18+
(a1 + a2) as sum_result,
19+
(a1 * a2) as mult_result,
20+
(a1 - a2) as sub_result,
21+
(a1 % 10) as mod_result
22+
FROM test;
23+
24+
-- name: ListTest5 :many
25+
SELECT
26+
COALESCE(a1 / 1024, 0) as with_inference,
27+
COALESCE(a2 / 1024, 0) as nullable_inference
28+
FROM test;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE test (
2+
id INT PRIMARY KEY AUTO_INCREMENT,
3+
a1 INT NOT NULL,
4+
a2 INT NULL,
5+
a3 FLOAT NOT NULL
6+
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "2"
2+
sql:
3+
- engine: "mysql"
4+
queries: "mysql/query.sql"
5+
schema: "mysql/schema.sql"
6+
gen:
7+
go:
8+
package: "mysql"
9+
out: "mysql"
10+
emit_json_tags: true
11+
emit_prepared_queries: false
12+
emit_interface: false
13+
emit_exact_table_names: false

0 commit comments

Comments
 (0)