PREPARE placeholder type coercion fails when plain queries work fine
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
Discovered this one while playing around with prepared statements. The type coercion of placeholders is different between a `PREPARE` statement and the normal query.
I.e,
The standard select query:
```sql
SELECT $1 = 'x', $1 = s FROM t
```
And
The prepared statement:
```sql
PREPARE p AS SELECT $1 = 'x', $1 = s FROM t
```
Both diverge in their placeholder resolution, and can fail in strange ways
### To Reproduce
This only appears when the types are potentially different. I.e, I saw it when the type on the table was `Utf8View` but literal strings are `Utf8`.
I did manage to replicate it using the datafusion cli.
I.e, first create a table definition (ensuring `map_string_types_to_utf8view` is on)
```sql
CREATE TABLE t(s VARCHAR) AS VALUES ('a');
```
Do the raw query (works fine):
```sql
SELECT $1 = 'x', $1 = s FROM t;
```
Prepare this query:
```sql
PREPARE p AS SELECT $1 = 'x', $1 = s FROM t;
```
This will error with:
```
Error during planning: Expected parameter of type Utf8, got Utf8View: Conflicting types for id $1
```
### Expected behavior
I'd expect this to work fine
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.