Skip to content

Failed to create prepared statement for insert-statement after called ToString method #14130

@ritalin

Description

@ritalin

What happens?

duckdb::Connection has Prepare method accepting duckdb::SQLStatement
Calling Prepare method after duckdb::SQLStatement::ToString led to throwing an exception:

GetUsingBinding: expected non-empty binding_name.

it seems to forget reverting alias property.

if (values_list) {
D_ASSERT(!default_values);
values_list->alias = string();
result += values_list->ToString();
} else if (select_statement) {

Is this expected feature?

To Reproduce

Code

auto db = duckdb::Duckdb(nullptr);
auto conn = duckdb::Connection(db);

// It supporses to exist `Foo` table
// `Foo` table is `CREATE TABLE Foo (id int primary key, name varchar, age int)`
std::string sql("INSERT INTO Foo values (1, 'qwerty', 42)";

// get parsed statements
auto stmts = conn.ExtractStatements(sql);
auto &stmt = stmts[0];

// Call Tostring
stmt->ToString();

// Call prepare
auto prepared_stmt = conn.Prepare(stmt); // <- `duckdb::InternalException` is throws here

Expected result

duckdb::unique_ptr<duckdb::PreparedStatement> is returned successfully.

Actual result

duckdb::InternalException is throws
from

throw InternalException("GetUsingBinding: expected non-empty binding_name");

Workaround

stmt->Copy()->ToString();
auto prepared_stmt = conn.Prepare(stmt);

OS:

MacOS Ventura 13.6.7 (x86_64 16GB RAM)

DuckDB Version:

1.1.0

DuckDB Client:

C++

Hardware:

No response

Full Name:

Kazuhiko TAMURA

Affiliation:

Free

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions