question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`insert into A select * from A`?

See original GitHub issue

It doesn’t seem possible to chain db.insertInto("A").selectFrom("A").selectAll().

It that possible in some other way? A workaround is to first fetch the rows from A and then insert them, however that incurs an extra roundtrip to the database.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
koskimascommented, Dec 15, 2021

This is now implemented and will be released with the next version. The typings are not as strict as the maybe could be. For example the types don’t complain about this:

db.insertInto('person')
  .columns(['first_name'])
  .expression(db.selectFrom('pet').select(['name', 'species']))
insert into "person" ("first_name")
select "name", "species" from "pet"

even though the SQL is incorrect. You can’t insert two values when only one (first_name) is listed. This is difficult to type correctly because of all the implicit type conversions done by database engines. We could ignore the types and only make sure there’s the same amount of columns in both, but even that is a bit tricky with typescript. We can enhance this later.

2reactions
koskimascommented, Dec 13, 2021

which weakens the library’s purpose

Really? Feel free to use knex 😉

db.selectFrom(...).values(...).set(...)

Do you really think it’s a problem that this is possible? Imagine a person that would write that. What would they think it would do? A person that writes that “query” clearly has no idea what SQL is. I don’t really see that being a problem even though it is possible. Theory is one thing, reality is another.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL INSERT INTO SELECT Statement - W3Schools
The INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that...
Read more >
SQL Server INSERT INTO SELECT By Practical Examples
In this syntax, the statement inserts rows returned by the query into the target_table . The query is any valid SELECT statement that...
Read more >
INSERT INTO SELECT statement overview and examples
Suppose we want to insert Top N rows from the source table to the destination table. We can use Top clause in the...
Read more >
SQL INSERT INTO SELECT Statement - Programiz
In SQL, the INSERT INTO SELECT statement is used to copy records from one table to another existing table. In this tutorial, we'll...
Read more >
INSERT INTO SELECT vs SELECT INTO In SQL Server
The INSERT INTO SELECT statement requires the target table to exist in the database before data can be transferred from the source table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found