Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL equal aggregate

I'd like to check that all (float) values of a set of records are equal. Something like

SELECT ..., equal(my_field) FROM my_table WHERE ... GROUP BY ...

Where equal(my_field) returns true if all values of my_field are equal.

like image 311
webshaker Avatar asked May 29 '26 22:05

webshaker


1 Answers

You could use MIN and MAX aggregates

SELECT min(field)=max(field) WHERE ... GROUP BY...

This doesn't take into account NULL values though. If those may be in the column you have to add a check for that.

Also remember that with floats equality is not always simple to check.

like image 118
Sami Kuhmonen Avatar answered Jun 01 '26 20:06

Sami Kuhmonen