Skip to content

Instantly share code, notes, and snippets.

View matthewlenz's full-sized avatar

Matthew Lenz matthewlenz

  • 13:19 (UTC -05:00)
View GitHub Profile
@DaveKin
DaveKin / json_uniq.sql
Last active October 24, 2023 18:25
SQL function to remove duplicate entries from a JSON array. Based on MYSQL 5.7+
CREATE FUNCTION JSON_UNIQ(arr JSON) RETURNS json
BEGIN
SET @arr = arr;
SET @a_length = JSON_LENGTH(@arr);
SET @loop_index = @a_length;
WHILE @loop_index >= 0 DO
SET @item = JSON_UNQUOTE(JSON_EXTRACT(@arr, concat('$[',@loop_index,']')));