Skip to content

Translate to GREATEST/LEAST in relational #31681

@roji

Description

@roji

Most/all relational database support GREATEST/LEAST, which accept an arbitrary number of parameters and return the greatest one. Note that unlike MAX/MIN, these aren't aggregate functions - they're just regular, non-aggregate variadic functions.

Database Functions Notes
PostgreSQL GREATEST/LEAST
MySQL GREATEST/LEAST
MariaDB GREATEST/LEAST
SQLite MAX/MIN These are non-aggregate with multiple arguments
SQL Server GREATEST/LEAST SQL Server 2022 and above
Oracle GREATEST/LEAST

We can add EF.Functions.{Greatest,Least} in relational to support these. Note that these would be similar to Math.Max and Min, which we should also translate; however, a custom EF.Functions.Greatest would provide the following advantages:

  • Support types for which Math.Max overloads don't exist (DateTime, string...)
  • Allow passing more than 2 arguments without nesting Math.Max calls, since these aren't variadic and support only two arguments.

Originally requested e.g. in npgsql/efcore.pg#2866

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions