Skip to content

INSERT INTO does not allow to insert only specified columns #8091

@karlovnv

Description

@karlovnv

Describe the bug

Most SQL databases (PG, MSSQL, ClickHouse, ...) allow to do INSERTS without resort to providing all the columns.

This is allowed by insert into TABLE(columns) VALUES (values) syntax when nullable columns could be omited.

It's important for upgrading schema of tables systems with zero downtime: on the first step we add new column and on the second we deploy new app code that deals with new schema.

Now it's impossible add column to schema without downtime due to logical planner error:
Error during planning: Inserting query must have the same schema with the table.

To Reproduce

create table foo(x int, y int);

insert into foo(x) values (10);

Expected:
(10, NULL) is inserted

Actual:

DataFusion CLI v32.0.0
❯ create table foo(x int, y int);
0 rows in set. Query took 0.002 seconds.

❯ insert into foo(x) values (10);
Error during planning: Inserting query must have the same schema with the table.

Expected behavior

row (10, NULL) is inserted

Additional context

Minimal repro without CLI:

use datafusion::prelude::*;

#[tokio::main]
async fn main() -> datafusion::error::Result<()> {
    let ctx = SessionContext::new();

    let queries = [
        "create table foo(x int, y int);",
        "insert into foo(x) values (10);",
        "insert into foo(x, y) values (10, 11);",
    ];
    for query in queries {
        let df = ctx.sql(query).await?;
        println!("> {query}");
        if let Err(err) = df.show().await {
            println!("{}", err);
        }
        
    }

    Ok(())
}


> create table foo(x int, y int);
++
++
> insert into foo(x) values (10);
Error during planning: Inserting query must have the same schema with the table.
> insert into foo(x, y) values (10, 11);
+-------+
| count |
+-------+
| 1     |
+-------+

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions