Created
July 20, 2014 18:42
-
-
Save ianstarz/529d1f1acc12f4a83559 to your computer and use it in GitHub Desktop.
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
/* will return null::json on empty resultset */ | |
SELECT array_to_json(array_agg(row_to_json(t))) FROM t; | |
/* | |
will return '[]' on empty resultset, | |
null::json seems to be managed the same way than sql NULL by COALESCE() | |
*/ | |
SELECT COALESCE(array_to_json(array_agg(row_to_json(t))), '[]') FROM t; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment