Skip to content

Commit 95835ee

Browse files
EliSauderCopilot
andcommitted
fix(mssql): take REPLICATE's and CHARINDEX's integer arguments as int
A placeholder for the count REPLICATE repeats a string, or the position CHARINDEX starts at, was a bigint, where SQL Server takes an int. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 13138f4 commit 95835ee

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
-- name: Trimmed :many
22
SELECT LEFT(a, 3) AS lf, RIGHT(c, @n) AS rt, TRIM(N'x' FROM a) AS tr, TRIM(LEADING 'x' FROM c) AS tl FROM p;
3+
4+
-- name: Repeated :many
5+
SELECT REPLICATE(a, @r) AS r, CHARINDEX(N'x', a, @ci) AS ci FROM p;

‎internal/endtoend/testdata/analyze_left_right_trim/mssql/stdout.json‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,45 @@
5151
}
5252
}
5353
]
54+
},
55+
{
56+
"name": "Repeated",
57+
"cmd": ":many",
58+
"columns": [
59+
{
60+
"name": "r",
61+
"type": {
62+
"name": "nvarchar",
63+
"nullable": true
64+
}
65+
},
66+
{
67+
"name": "ci",
68+
"type": {
69+
"name": "int",
70+
"nullable": true
71+
}
72+
}
73+
],
74+
"params": [
75+
{
76+
"number": 1,
77+
"column": {
78+
"name": "r",
79+
"type": {
80+
"name": "int"
81+
}
82+
}
83+
},
84+
{
85+
"number": 2,
86+
"column": {
87+
"name": "ci",
88+
"type": {
89+
"name": "int"
90+
}
91+
}
92+
}
93+
]
5494
}
5595
]

‎internal/engine/mssql/dialect/functions.jsonl‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@
124124
{"name": "replace", "args": [{"type": "nchar"}, {"type": "any"}, {"type": "any"}], "returns": "nvarchar(4000)", "nullable": true}
125125
{"name": "translate", "args": [{"type": "varchar"}, {"type": "any"}, {"type": "any"}], "returns": "varchar(8000)", "nullable": true}
126126
{"name": "translate", "args": [{"type": "nvarchar"}, {"type": "any"}, {"type": "any"}], "returns": "nvarchar(4000)", "nullable": true}
127-
{"name": "replicate", "args": [{"type": "varchar"}, {"type": "bigint"}], "returns": "varchar", "nullable": true}
128-
{"name": "replicate", "args": [{"type": "char"}, {"type": "bigint"}], "returns": "varchar", "nullable": true}
129-
{"name": "replicate", "args": [{"type": "nvarchar"}, {"type": "bigint"}], "returns": "nvarchar", "nullable": true}
130-
{"name": "replicate", "args": [{"type": "nchar"}, {"type": "bigint"}], "returns": "nvarchar", "nullable": true}
127+
{"name": "replicate", "args": [{"type": "varchar"}, {"type": "int"}], "returns": "varchar", "nullable": true}
128+
{"name": "replicate", "args": [{"type": "char"}, {"type": "int"}], "returns": "varchar", "nullable": true}
129+
{"name": "replicate", "args": [{"type": "nvarchar"}, {"type": "int"}], "returns": "nvarchar", "nullable": true}
130+
{"name": "replicate", "args": [{"type": "nchar"}, {"type": "int"}], "returns": "nvarchar", "nullable": true}
131131
{"name": "reverse", "args": [{"type": "varchar"}], "returns": "$1", "nullable": true}
132132
{"name": "reverse", "args": [{"type": "char"}], "returns": "varchar", "nullable": true}
133133
{"name": "reverse", "args": [{"type": "nvarchar"}], "returns": "$1", "nullable": true}
@@ -138,7 +138,7 @@
138138
{"name": "stuff", "args": [{"type": "nchar"}, {"type": "bigint"}, {"type": "bigint"}, {"type": "any"}], "returns": "nvarchar", "nullable": true}
139139
{"name": "space", "args": [{"type": "int"}], "returns": "varchar(8000)", "nullable": true}
140140
{"name": "charindex", "args": [{"type": "any"}, {"type": "any"}], "returns": "int", "nullable": true}
141-
{"name": "charindex", "args": [{"type": "any"}, {"type": "any"}, {"type": "bigint"}], "returns": "int", "nullable": true}
141+
{"name": "charindex", "args": [{"type": "any"}, {"type": "any"}, {"type": "int"}], "returns": "int", "nullable": true}
142142
{"name": "patindex", "args": [{"type": "any"}, {"type": "any"}], "returns": "int", "nullable": true}
143143
{"name": "ascii", "args": [{"type": "varchar"}], "returns": "int", "nullable": true}
144144
{"name": "unicode", "args": [{"type": "nvarchar"}], "returns": "int", "nullable": true}

0 commit comments

Comments
 (0)