Table of Contents

Class Least

Namespace
YndigoBlue.Velocity.Functions
Assembly
YndigoBlue.Velocity.dll

Represents the LEAST function, which returns the smallest of two or more values.

public class Least : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
Inheritance
Least
Implements

Remarks

LEAST compares values across a row, unlike the Min aggregate which finds the smallest value down a column across many rows. LEAST(price, cap_price) yields one value per row; MIN(price) yields one value for the whole group.

NULL handling differs by datasource and Velocity does not normalize it.

NULL arguments ignoredPostgreSQL, SQL Server
Any NULL makes the whole result NULLOracle, MySQL, DB2, SQLite, Teradata

Velocity deliberately does not inject a NULL guard of its own: doing so would silently change the meaning of a query that genuinely wants a NULL to propagate, and would make this function mean something different from the LEAST every one of these databases documents. Where a missing value has a defined meaning, wrap the arguments in Coalesce — that yields identical results on every datasource. See Greatest for a worked example of that idiom.

Rendered as LEAST on every supported datasource except SQLite, which spells the same operation as its multi-argument scalar MIN. Note that SQL Server gained LEAST in SQL Server 2022 (16.x); earlier versions do not support it.

Examples

Capping a discount at the lower of two limits:

var schema = manager.LoadSchema("sales");
var orders = schema["orders"];

var query = new Query()
    .Select([ orders["order_id"], new Expression("applied_discount", new Least([ orders["discount"], orders["max_discount"] ])) ])
    .From(orders);

var results = manager.Retrieve(query);

// SQL: SELECT order_id, LEAST(discount, max_discount) AS applied_discount FROM orders

Constructors

Least(IEnumerable<IElement>)

Initializes a new instance of LEAST with a collection of elements.