Last active
March 15, 2018 20:00
-
-
Save jhannah/30e54bbf9963a9ca4bb0af8edfd4a04b to your computer and use it in GitHub Desktop.
PostgreSQL 10.3 coalesce vs. greatest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table t; | |
create table t(c1 int, c2 int); | |
insert into t values (1, null), (2, null), (null, 7), (null, 4), (3, 20); | |
# select * from t; | |
c1 | c2 | |
----+---- | |
1 | | |
2 | | |
| 7 | |
| 4 | |
3 | 20 | |
(5 rows) | |
# select max(coalesce(c1,c2)) from t; | |
max | |
----- | |
7 | |
# select max(greatest(c1, c2)) from t; | |
max | |
----- | |
20 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment