-
-
Notifications
You must be signed in to change notification settings - Fork 496
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 for selecting from an ad-hoc table with parameterized data? #152
Comments
For those databases that don't support ad-hoc queries via SELECT 1 AS a, 2 AS b, 3 AS c
UNION ALL
SELECT 4, 5, 6; |
Thanks for the suggestion, I think the |
Or perhaps just an overload of With(string alias, IEnumerable<string> columns, IEnumerable<object> values) since |
@freakingawesome I think you mean With(string alias, IEnumerable<string> columns, IEnumerable<IEnumerable<object>> values) right ? |
Both should arguably be supported. If we were to model it based off the With(object data)
With(IEnumerable<string> columns, IEnumerable<object> values)
With(IReadOnlyDictionary<string, object> data)
With(IEnumerable<string> columns, IEnumerable<IEnumerable<object>> valuesCollection) |
If I get it well, we need to load more than one row to simulate the matrix,
the following overloads allows us to insert just one row: With(object data)
With(IEnumerable<string> columns, IEnumerable<object> values)
With(IReadOnlyDictionary<string, object> data) so we only have this overload that accept a list of list With(IEnumerable<string> columns, IEnumerable<IEnumerable<object>> valuesCollection) as a valid use case |
My mistake - you're absolutely right. I had thought the other overloads were doing more reflection introspection than they actually are. I agree that the only overload we'd need is With(IEnumerable<string> columns, IEnumerable<IEnumerable<object>> valuesCollection) |
I often come across the need to pass in a "table" of data into a query. In the past I've done string concatenation to create a temporary table (or table variable), then added an INSERT with multiple rows of values. After playing with sqlkata for some time (which I love, by the way), I think there could be a more intuitive way of building such a temporary table, and without actually building a temporary table.
For example, both SQL Server and PostgreSQL allow arbitrary tables of the form:
SQL Server:
PostgreSQL:
Both the above queries return a table of the following form:
To me, this feels like a perfect fit for sqlkata, as a subquery and/or inside a CTE. It has the feel of
Insert()
syntax. Perhaps it could be expressed as something like this?If there is interest in this idea, I would happily take a stab at building it out and submitting a PR (it is Hacktoberfest, after all!).
The text was updated successfully, but these errors were encountered: