Reading on the web, about PostgreSQL arrays as the type for table columns, I have found that the general reaction or opinion among developers is: “Do not use arrays, better use another table because that scales better”.
…I understand that, that is what I have basically done always.
And I have never found any case where developers can agree that an array would be the most appropriate. Is there any case where using an array is really worth it?
You can find examples of Postgresql arrays in its internal tables (namely
pg_classpg_constraint).Arrays would be appropriate if:
Your DB driver/connection/application manages them correctly (not all of them do).
You do not need to filter/query the data in the array (you need all the data in the array or you do not need it at all).
So, the perfect example –
pg_constraint.conkey:Postgres can handle its arrays correctly 🙂
It need all the columns to check them (or do not need them at all if no check is applied)
UPD: And in all cases of “appropriate” use of arrays, I can think of, they are always small 0-10 elements arrays.