Skip to content

Commit aba9134

Browse files
committed
adapter: Don't panic when the same parameter is coerced twice
1 parent 40afbe8 commit aba9134

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

src/sql/src/plan/typeconv.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use dynfmt::{Format, SimpleCurlyFormat};
1818
use itertools::Itertools;
1919
use mz_expr::func::{CastArrayToJsonb, CastListToJsonb};
2020
use mz_expr::{VariadicFunc, func};
21-
use mz_ore::assert_none;
2221
use mz_repr::{ColumnName, ColumnType, Datum, RelationType, ScalarBaseType, ScalarType};
2322

2423
use crate::catalog::TypeCategory;
@@ -1134,7 +1133,16 @@ pub fn plan_coerce<'a>(
11341133

11351134
Parameter(n) => {
11361135
let prev = ecx.param_types().borrow_mut().insert(n, coerce_to.clone());
1137-
assert_none!(prev);
1136+
if let Some(prev) = prev {
1137+
if prev != *coerce_to {
1138+
sql_bail!(
1139+
"there are contradicting constraints for the type of parameter ${}: should be both {} and {}",
1140+
n,
1141+
ecx.humanize_scalar_type(&prev, false),
1142+
ecx.humanize_scalar_type(coerce_to, false),
1143+
);
1144+
}
1145+
}
11381146
HirScalarExpr::parameter(n)
11391147
}
11401148
})

test/sqllogictest/prepare.slt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,63 @@ SELECT * FROM t;
6060
4
6161
5
6262
6
63+
64+
statement ok
65+
PREPARE p1 AS
66+
SELECT $1 + $1::bigint;
67+
68+
query I
69+
EXECUTE p1(5);
70+
----
71+
10
72+
73+
statement ok
74+
PREPARE p2 AS
75+
SELECT $1::bigint + $1::bigint;
76+
77+
query I
78+
EXECUTE p2(7);
79+
----
80+
14
81+
82+
statement ok
83+
PREPARE p3 AS
84+
SELECT $1 || $1;
85+
86+
query T
87+
EXECUTE p3('abc');
88+
----
89+
abcabc
90+
91+
statement ok
92+
PREPARE p4 AS
93+
SELECT $1::text || $1::bigint::text;
94+
95+
query error db error: ERROR: invalid input syntax for type bigint: invalid digit found in string: "abc"
96+
EXECUTE p4('abc');
97+
98+
query T
99+
EXECUTE p4('123');
100+
----
101+
123123
102+
103+
statement ok
104+
PREPARE p5 AS
105+
SELECT $1, $1::bigint;
106+
107+
query II
108+
EXECUTE p5(7);
109+
----
110+
0
111+
7
112+
113+
query error db error: ERROR: operator does not exist: bigint \|\| bigint
114+
PREPARE p6 AS
115+
SELECT $1 + $1::bigint, $1 || $1;
116+
117+
query error db error: ERROR: operator does not exist: text \+ bigint
118+
PREPARE p7 AS
119+
SELECT $1 || $1, $1 + $1::bigint;
120+
121+
query error db error: ERROR: there are contradicting constraints for the type of parameter \$1: should be both text and integer
122+
PREPARE p AS SELECT repeat($1, $1);

0 commit comments

Comments
 (0)