diff --git a/src/sql/src/plan/typeconv.rs b/src/sql/src/plan/typeconv.rs index c4abe14723a1e..60cbe2dd5e04e 100644 --- a/src/sql/src/plan/typeconv.rs +++ b/src/sql/src/plan/typeconv.rs @@ -18,7 +18,6 @@ use dynfmt::{Format, SimpleCurlyFormat}; use itertools::Itertools; use mz_expr::func::{CastArrayToJsonb, CastListToJsonb}; use mz_expr::{VariadicFunc, func}; -use mz_ore::assert_none; use mz_repr::{ColumnName, ColumnType, Datum, RelationType, ScalarBaseType, ScalarType}; use crate::catalog::TypeCategory; @@ -1134,7 +1133,16 @@ pub fn plan_coerce<'a>( Parameter(n) => { let prev = ecx.param_types().borrow_mut().insert(n, coerce_to.clone()); - assert_none!(prev); + if let Some(prev) = prev { + if prev != *coerce_to { + sql_bail!( + "there are contradicting constraints for the type of parameter ${}: should be both {} and {}", + n, + ecx.humanize_scalar_type(&prev, false), + ecx.humanize_scalar_type(coerce_to, false), + ); + } + } HirScalarExpr::parameter(n) } }) diff --git a/test/sqllogictest/prepare.slt b/test/sqllogictest/prepare.slt index 6a36bf058bb73..a6dcfc0d79fb0 100644 --- a/test/sqllogictest/prepare.slt +++ b/test/sqllogictest/prepare.slt @@ -60,3 +60,63 @@ SELECT * FROM t; 4 5 6 + +statement ok +PREPARE p1 AS +SELECT $1 + $1::bigint; + +query I +EXECUTE p1(5); +---- +10 + +statement ok +PREPARE p2 AS +SELECT $1::bigint + $1::bigint; + +query I +EXECUTE p2(7); +---- +14 + +statement ok +PREPARE p3 AS +SELECT $1 || $1; + +query T +EXECUTE p3('abc'); +---- +abcabc + +statement ok +PREPARE p4 AS +SELECT $1::text || $1::bigint::text; + +query error db error: ERROR: invalid input syntax for type bigint: invalid digit found in string: "abc" +EXECUTE p4('abc'); + +query T +EXECUTE p4('123'); +---- +123123 + +statement ok +PREPARE p5 AS +SELECT $1, $1::bigint; + +query II +EXECUTE p5(7); +---- +0 +7 + +query error db error: ERROR: operator does not exist: bigint \|\| bigint +PREPARE p6 AS +SELECT $1 + $1::bigint, $1 || $1; + +query error db error: ERROR: operator does not exist: text \+ bigint +PREPARE p7 AS +SELECT $1 || $1, $1 + $1::bigint; + +query error db error: ERROR: there are contradicting constraints for the type of parameter \$1: should be both text and integer +PREPARE p AS SELECT repeat($1, $1);