Last active
February 11, 2019 14:10
-
-
Save Astyk/91518ba7f1b177ad4ba8ea09b021c453 to your computer and use it in GitHub Desktop.
JSON_ARRAYAGG
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
DELIMITER // | |
DROP FUNCTION IF EXISTS JSON_ARRAYAGG// | |
CREATE AGGREGATE FUNCTION IF NOT EXISTS JSON_ARRAYAGG(next_value TEXT) RETURNS TEXT | |
BEGIN | |
DECLARE json TEXT DEFAULT '[""]'; | |
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN json_remove(json, '$[0]'); | |
LOOP | |
FETCH GROUP NEXT ROW; | |
SET json = json_array_append(json, '$', next_value); | |
END LOOP; | |
END // | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment