Posts

Showing posts with the label least

LEAST() and GREATEST() - Postgres SQL Amazing But Rarely Known Functions .

PostgresSQL is very powerful and one of the world's most advanced open-source relational databases. It gives much more flexibility and customization on query level when you want to perform a complex operation or complex queries on the database. Postgresql provides multiple operators and functions which make even complex operations and complex queries pretty easy and simple. Similarly LEAST() and GREATEST() are functions that make your work very easy and simple. LEAST() and GREATEST() functions are very useful when you want to operate on different columns within the same row (a record) in a table. LEAST() and GREATEST() compare and find the minimum and maximum value respectively among given columns values in the same row. It's similar to finding a minimum or maximum value from an array of given values. Here are a few simple examples you can try: select LEAST(5, 3, 9, 2, 8, 1) and GREATEST(5, 3, 9, 2, 8, 1); //should give 1 and 9 respectively In-case of String or Varchar, it gi...