PostgreSQL MIN() function is an aggregate function that returns the minimum value in a set of values. Syntax: MIN(expression); The MIN() function can be used with SELECT, WHERE and HAVING clause.
To get the maximum value from three different columns, use the GREATEST() function. Insert some records in the table using insert command. Display all records from the table using select statement.
PostgreSQL MAX() function is an aggregate function that returns the maximum value in a set of values. Syntax: MAX(expression); The MAX() function can be used with SELECT, WHERE and HAVING clause.
PostgreSQL allows a type of integer type namely SMALLINT . It requires 2 bytes of storage size and can store integers in the range of -37, 767 to 32, 767. It comes in handy for storing data like the age of people, the number of pages in a book, etc. Syntax: variable_name SMALLINT.
Have a look at GREATEST and LEAST.
UPDATE my_table
SET my_column = GREATEST(my_column - 10, 0);
You want the inline sql case
:
set my_column = case when my_column - 10 > 0 then my_column - 10 else 0 end
max()
is an aggregate function and gets the maximum of a row of a result set.
Edit: oops, didn't know about greatest
and least
in postgres. Use that instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With