Skip to content

PREPARE placeholder type coercion fails when plain queries work fine #22506

@cetra3

Description

@cetra3

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:

SELECT $1 = 'x', $1 = s FROM t

And

The prepared statement:

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)

CREATE TABLE t(s VARCHAR) AS VALUES ('a');

Do the raw query (works fine):

SELECT $1 = 'x', $1 = s FROM t;

Prepare this query:

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions