PostgreSQL Database Design – When to Use JSON or JSONB Array vs SQL Array

arraydatabase-designpostgresql

I am looking for the main points to consider when choosing between a JSON or JSONB array and the regular SQL postgres array. If you know that you will only be inserting one data type into an array, why would you use the SQL array over the JSON array? Thanks

Best Answer

I think this is mainly a matter of personal preference, so I guess your question will be closed soon.

If you deal with JSON values in your application anyway, going with JSON might be easier (but then you can easily convert a native array to a json array using to_jsonb()).

There are a bit more functions for changing native arrays than there are for JSON arrays. So if you need to remove or find elements by value, native arrays might be easier. If those arrays contain integers, you can have even more functions for manipulating them through the intarray extension

And then of course there is the underlying question: wouldn't a properly normalized model be the best solution anyways, so that you avoid arrays completely?