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

[10.x] allow insert..select (insertUsing()) to have empty $columns #46605

Merged
merged 1 commit into from
Mar 28, 2023

Conversation

jonnott
Copy link
Contributor

@jonnott jonnott commented Mar 27, 2023

Enables queries which insert all columns from the source table into the destination table, e.g. "insert into users select * from users”, when the table schemas exactly match.

(alter testPreservedAreAppliedByInsertUsing() to not conflict with new behaviour)

Enables queries which insert *all* columns from the source table into the destination table, e.g. "insert into users select * from users”, when the table schemas exactly match.

alter testPreservedAreAppliedByInsertUsing() to not conflict with new behaviour
@taylorotwell
Copy link
Member

I wonder if we should add a new helper method for this so you don't have to pass an empty array?

@taylorotwell
Copy link
Member

Updated to also allow ['*'] for columns.

@jonnott
Copy link
Contributor Author

jonnott commented Mar 29, 2023

I wonder if we should add a new helper method for this so you don't have to pass an empty array?

@taylorotwell Aha, I see the genius of your addition .. as you can't specify * for the INSERT part of an INSERT..SELECT because MySQL (at least) doesn't like it..

e.g. insert into users_archive (*) select * from users will result in:

Query 1 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) select * from users' at line 1

..you've made it also omit the columns part if $columns is ['*'], therefore making it more developer-friendly, whilst also avoiding the syntax error.

Good job!

@jonnott jonnott deleted the patch-1 branch March 29, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants