Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/sql/src/plan/typeconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
})
Expand Down
60 changes: 60 additions & 0 deletions test/sqllogictest/prepare.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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);