Skip to content
Advertisement

SQLite equivalent of PostgreSQL’s GREATEST function

PostgreSQL has a useful function called GREATEST. It returns the largest value of those passed to it as documented here.

Is there any equivalent in SQLite?

As a note, I only need it to work with 2 arguments.

Advertisement

Answer

SELECT MAX(1,2,..)

ref: https://sqlite.org/lang_corefunc.html#maxoreunc

max(X,Y,...)

The multi-argument max() function returns the argument with the maximum value, or return NULL if any argument is NULL. The multi-argument max() function searches its arguments from left to right for an argument that defines a collating function and uses that collating function for all string comparisons. If none of the arguments to max() define a collating function, then the BINARY collating function is used. Note that max() is a simple function when it has 2 or more arguments but operates as an aggregate function if given only a single argument.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement