2

Is there a function in mysql to sort a json field?

SELECT new FROM mytable
["orange", "apple"]

==> Sorting the json array

SELECT SORTED(new) FROM mytable
["apple", "orange"]
6
  • I don't think so. All the JSON functions are listed here Commented Dec 8, 2018 at 0:14
  • I see lots of questions from you about MySQL JSON. Just because this is available, I don't think you should overuse it. It would be better if you normalized your schema using traditional SQL design. Commented Dec 8, 2018 at 0:16
  • @Barmar right, yea this is a denormalized field of another table that we use on a ListAll() call, so we're storing a denormalized json field to improve read performance, etc... Commented Dec 8, 2018 at 0:19
  • @Barmar do you think there would a way to do this by perhaps unnesting the array and then nesting it again? Commented Dec 8, 2018 at 0:56
  • 1
    I don't know a way of unnesting the array in MySQL. Don't use JSON for this kind of thing. If it were in a normalized table you could use ORDER BY. Commented Dec 8, 2018 at 1:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.