Repository navigation
Closed
Description
Feature Description
Allow InsertQueryBuilder to use SELECT.
The Problem
Following code can't be generated using QueryBuilder
INSERT INTO foo(name)
SELECT "name" FROM other_tableThe Solution
Obvious solution would be to use something like:
connection.getRepository(foo)
.insert()
.from(OtherTable, 'other_table')
.innerJoin(YetAnotherTable, 'yet_another_table', 'other_table ... = yet_another_table ...')
.where('...')Easier to implement would be:
class InsertQueryBuilder<T = any> {
from(queryBuilder: QueryBuilder<any>, alias?: string, columnNames?: (keyof T)[]);
}and generate query like
INSERT INTO foo(name)
SELECT alias.name
FROM (
SELECT "name" FROM other_table
) aliasConsidered Alternatives
Use other query builder library of construct query manually.
Additional Context
(redacted for clarity)
INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]
{ query }Relevant Database Driver(s)
| DB Type | Relevant |
|---|---|
aurora-data-api |
yes |
aurora-data-api-pg |
yes |
better-sqlite3 |
yes |
cockroachdb |
yes |
cordova |
yes |
expo |
yes |
mongodb |
yes |
mysql |
yes |
nativescript |
yes |
oracle |
yes |
postgres |
yes |
react-native |
yes |
sap |
yes |
sqlite |
yes |
sqlite-abstract |
yes |
sqljs |
yes |
sqlserver |
yes |
Are you willing to resolve this issue by submitting a Pull Request?
- ✅ Yes, I have the time, and I know how to start.
- ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
Reacted by GP4cK, Corentin Hatte, Moustafa Attia, Desiders and Anja Lea Brinkmann
Metadata
Metadata
Assignees
Labels
No labels
Activity
mortezaPRK commentedon Aug 17, 2022
@Ginden I need this feature and also the one mentioned in #8542.
Do you plan to create a PR for it? if not, I'm ready to it.
Ginden commentedon Aug 17, 2022
You will probably be faster, because I will be busy at least until end of September.
PurpleTape commentedon Feb 4, 2024
Any updates? 🥺🥺🥺
rohitkhatri commentedon Jul 10, 2024
Any update on this?
VMolokostovEnergiAI commentedon Nov 7, 2024
Anything so far?
Ginden commentedon Nov 7, 2024
None, I'm not at company using TypeORM anymore.
JTBrinkmann commentedon Jan 3, 2025
this duplicates #4374
github-actions commentedon Sep 18, 2025
TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).
As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.
🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.
OverWeo commentedon Nov 13, 2025
Any updates?
Moustafa3attia commentedon Mar 16, 2026
Still relevant