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

Allow expressing VALUES expressions #2174

Closed
roji opened this issue Dec 20, 2021 · 4 comments
Closed

Allow expressing VALUES expressions #2174

roji opened this issue Dec 20, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@roji
Copy link
Member

roji commented Dec 20, 2021

PostgreSQL supports the following expression: VALUES (1, 'one'), (2, 'two'), (3, 'three'). This is a table-returning expression which can be used anywhere a table can (e.g. in subqueries, JOINs), and can be useful for specifying constant tables. Note that this syntax makes up the standard SQL INSERT statement (it's what comes after INSERT INTO foo (<columns>) ...).

As part of EF Core 7.0 we may add row value expressions (see dotnet/efcore#26822). If that's done, a PostgreSQL-specific ValuesExpression could be added, which is just a collection of RowValueExpressions.

/cc @smitpatel

Originally requested in https://stackoverflow.com/questions/70411262/constant-tables-in-ef-or-npgsql

@roji roji added the enhancement New feature or request label Dec 20, 2021
@roji roji added this to the Backlog milestone Dec 20, 2021
@smarts
Copy link

smarts commented Nov 16, 2023

Would completion of this issue include enabling VALUES expressions in the ANY(…) operator? And if not, is there a separate issue for this functionality that I can upvote?

@roji roji modified the milestones: Backlog, 8.0.0 Nov 17, 2023
@roji roji self-assigned this Nov 17, 2023
@roji
Copy link
Member Author

roji commented Nov 17, 2023

This was actually done for EF 8.0 in dotnet/efcore#30426.

Specifically for Contains, see dotnet/efcore#30732; I'm not sure why you'd want to use VALUES in ANY, when you can simply use x IN (a, b, c) directly (the list inside IN functions just like VALUES). Am I missing something?

@roji roji closed this as completed Nov 17, 2023
@smarts
Copy link

smarts commented Nov 21, 2023

@roji if you have a composite key (and therefore index) like ParentId, ChildId i believe using WHERE ("ParentId", "ChildId") in (VALUES(45, 67), VALUES(12, 34)) allows the index to be used.
Edit: I think my syntax is off here. The VALUES keyword isn't necessary in the example above

@roji
Copy link
Member Author

roji commented Nov 21, 2023

The VALUES keyword isn't necessary in the example above

Exactly, there's no need for it.

Other than that, no, this does not allow for embedding multiple row-values inside IN - nor is that supported anywhere else at the moment. That would mean supporting complex collections, which EF doesn't support yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants