Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow columns to be specified in insert statements #2859

Open
talagluck opened this issue Apr 5, 2024 · 5 comments
Open

allow columns to be specified in insert statements #2859

talagluck opened this issue Apr 5, 2024 · 5 comments
Assignees
Labels
syntax Issues or features related to our SQL syntax

Comments

@talagluck
Copy link
Contributor

Description

I would expect this to work:

  insert into my_table ("column1", "column2", "column3")
        select "column1", "column2", "column3"
        from my_other_table
  

But it currently doesn't work if you specify the columns. This isn't necessarily how I would intuitively choose to do it, but it is how the dbt postgres adapter compiles incrementally materialized models, so fixing this would enable that feature.

@talagluck talagluck added the bug 🐛 Something isn't working label Apr 5, 2024
@tychoish tychoish changed the title Bug: columns can't be specified in inserts allow columns to be specified in insert statements Apr 9, 2024
@tychoish tychoish added syntax Issues or features related to our SQL syntax and removed bug 🐛 Something isn't working labels Apr 9, 2024
@vrongmeal vrongmeal self-assigned this Apr 22, 2024
@vrongmeal
Copy link
Contributor

> create table my_table as values (1, 2, 3, 4, 5);
Table created

> create table my_other_table as values (10, 20, 30, 40);
Table created

> select column1, column2, column3 from my_other_table;
┌─────────┬─────────┬─────────┐
│ column1 │ column2 │ column3 │
│      ── │      ── │      ── │
│   Int64 │   Int64 │   Int64 │
╞═════════╪═════════╪═════════╡
│      10 │      20 │      30 │
└─────────┴─────────┴─────────┘

> select * from my_table;
┌─────────┬─────────┬─────────┬─────────┬─────────┐
│ column1 │ column2 │ column3 │ column4 │ column5 │
│      ── │      ── │      ── │      ── │      ── │
│   Int64 │   Int64 │   Int64 │   Int64 │   Int64 │
╞═════════╪═════════╪═════════╪═════════╪═════════╡
│       1 │       2 │       3 │       4 │       5 │
└─────────┴─────────┴─────────┴─────────┴─────────┘

> insert into my_table ("column1", "column2", "column3")
:::         select "column1", "column2", "column3"
:::         from my_other_table;
Inserted 1 row

> select * from my_table;
┌─────────┬─────────┬─────────┬─────────┬─────────┐
│ column1 │ column2 │ column3 │ column4 │ column5 │
│      ── │      ── │      ── │      ── │      ── │
│   Int64 │   Int64 │   Int64 │   Int64 │   Int64 │
╞═════════╪═════════╪═════════╪═════════╪═════════╡
│      10 │      20 │      30 │    NULL │    NULL │
│       1 │       2 │       3 │       4 │       5 │
└─────────┴─────────┴─────────┴─────────┴─────────┘

This works for me. I suppose Datafusion fixed this. @talagluck where/when did you face this error?

@tychoish
Copy link
Collaborator

can you put this in as an SLT?

@vrongmeal
Copy link
Contributor

Sure, will do!

@talagluck
Copy link
Contributor Author

Yes, I'm having trouble reproducing now, and I'm not sure whether it was fixed in Datafusion, or whether I was just hitting multiple errors at the same time. We can close this once the SLTis added.

@tychoish
Copy link
Collaborator

tychoish commented May 6, 2024

@talagluck do you want to add the SLT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
syntax Issues or features related to our SQL syntax
Projects
None yet
Development

No branches or pull requests

3 participants