Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 318
Alex Gaynor Avatar asked Jan 30 '10 03:01

Alex Gaynor


People also ask

Is SQLite faster than Postgres?

The following chart shows the response time for PostgreSQL (blue) and SQLite (red), with a single client. Here it is very clear that PostgreSQL returns results faster, and is especially efficient for shorter queries.

Which is better SQLite or PostgreSQL?

PostgreSQL is the way to go for high customizability and specific database requirements, and SQLite is the best option for an application with low DB storage needs or a website with low traffic.

Does SQLite support a BLOB type?

(10) Does SQLite support a BLOB type? SQLite allows you to store BLOB data in any column, even columns that are declared to hold some other type. BLOBs can even be used as PRIMARY KEYs.

Is SQLite the best?

For device-local storage with low writer concurrency and less than a terabyte of content, SQLite is almost always a better solution. SQLite is fast and reliable and it requires no configuration or maintenance.


1 Answers

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.

like image 76
Matthew Avatar answered Sep 23 '22 17:09

Matthew