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

Support alias in insert into #4003

Closed
biern opened this issue Apr 16, 2019 · 5 comments · Fixed by #8791
Closed

Support alias in insert into #4003

biern opened this issue Apr 16, 2019 · 5 comments · Fixed by #8791

Comments

@biern
Copy link

biern commented Apr 16, 2019

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue

Database system/driver:

[x] postgres

PostgreSQL supports alias in INSERT INTO statement since v9.5, eg. INSERT INTO "tablename" as "alias" (https://www.postgresql.org/docs/9.5/sql-insert.html). It would be nice to be able to use that in insert query builder.

Our use case is incrementing a counter using INSERT ... ON CONFLICT statement and using table prefixes at the same time. eg:

this.createQueryBuilder()
      .insert()
      .into(Velocity)
      .values(velocity)
      .onConflict(
        `("date", "symbol") DO UPDATE SET value = v1_velocity.value + :velocity `
      )
      .setParameter('velocity', velocity.value)
      .execute();

v1_ is our prefix here and it shouldn't have to be hardcoded in the query. I think we can workaround this by using this.manager.connection.driver.options.entityPrefix but I think that using explicit alias would be clearer.

@tonyxiao
Copy link

To confirm, you mean INSERT INTO "tablename" as "alias" right? If so 👍

@biern
Copy link
Author

biern commented May 19, 2019

@tonyxiao yes, thanks for pointing this out, I've updated the issue to include that explicit statement example.

@antoine-pous
Copy link

Oh! i was looking for exactly this feature :'(

@kyle-seongwoo-jun
Copy link

any updates?

@falahati
Copy link

not having this makes the ON CONFLICT DO UPDATE unusable. Please take another look at this issue.

zbarbuto added a commit to NextFaze/typeorm that referenced this issue Mar 24, 2022
zbarbuto added a commit to NextFaze/typeorm that referenced this issue Mar 24, 2022
zbarbuto added a commit to NextFaze/typeorm that referenced this issue Mar 24, 2022
zbarbuto added a commit to NextFaze/typeorm that referenced this issue Mar 24, 2022
zbarbuto added a commit to NextFaze/typeorm that referenced this issue Mar 24, 2022
zbarbuto added a commit to NextFaze/typeorm that referenced this issue Mar 24, 2022
M-TGH pushed a commit to TradeCast/typeorm that referenced this issue Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants