Skip to content

Formatting a SELECT list for INSERT INTO SELECT usage #42

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

Closed
ThomasLobker opened this issue May 31, 2019 · 1 comment
Closed

Formatting a SELECT list for INSERT INTO SELECT usage #42

ThomasLobker opened this issue May 31, 2019 · 1 comment
Labels

Comments

@ThomasLobker
Copy link

If you have complex queries and you want to INSERT from a SELECT query, then you need to be able to set a SELECT list like this:

INSERT INTO `table`
SELECT
  NULL `id`,
  'Thomas' `name`,
  34 `age`
WHERE 1

What is currently the best way to create such a SELECT list from an object? The following statement does not work in this scenario and creates a key = value list:

sqlstring.format('INSERT INTO `table` SELECT ?? WHERE 1', { id: null, name: "Thomas", age: 34 });
@dougwilson
Copy link
Member

This is unfortunately not really supported out of the box, and due to recent highlights of the insecurity of magical formatting based on the input type, it is unlikely to be added to this module. I would recommend looking in to a full-feature SQL builder module like https://hiddentao.github.io/squel/v4/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants