java - PostgreSQL - integer[] best practice -
working on web app lately decided use integer[] in data model. having 2 tables, 1 articles' data , second tags (tag id , description), decided tag ids article tagged in article.tags integer[] column.
as milen a. radev pointed out:
tip: arrays not sets; searching specific array elements can sign of database misdesign. consider using separate table row each item array element. easier search, , scale better large number of elements.
not that, having work integer[] using jdbc , ibatis turned out, shall "interesting".
for moment, can away working implementation in place had do. re-worked simplicity's sake using separate table storing article.id , tag.id relationships.
in end i'm puzzled integer[] best used , in context?
i think figured out hard way it's not best for.
imho, since array violation of 1nf, best context is:... (drumroll)..... none.
this gets question of why have data not meant queried. values potentially searchable, , if not supposed use array on searchable values, again led conclusion never worth using.
this leaves hypothetical case storing array solely purpose of analysis , manipulation on client. i'm sure these exist, not in experience.
edit: above said, "i'm sure these exist..." @ @mu short's answer example.
Comments
Post a Comment