The following case
[{type: x, val: y}, {...}, {...}, ...]
can be represented by JSONField alone.
Also, the following case
[1,2,3,4,5]
can be represented by JSONField.
Then what is the point of using ArrayField?
Am I correct to assume JSONField covers all the cases of ArrayField?
No, you're not correct in that assumption. You can make PostgreSQL arrays of any type that PostgreSQL supports but JSON only supports strings, integers, floating point numbers, booleans, JavaScript-style objects, and arrays.
For example, you can create an array of timestamps or dates but to store those types in JSON you end converting them to strings (or sometimes numbers) and store those strings. Then, if you need to use the time functions or operators, you'd have to dig the strings out of the JSON arrays, convert them into timestamps or dates, and finally apply the functions or operators.
Similarly for all the other data types that PostgreSQL understands that JSON doesn't.
The array functions and operators and JSON (array) functions and operators are comparable but the data types are not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With