/    Sign up×
Community /Pin to ProfileBookmark

Store an array in a single column

I’m needing to store an array in my database. I could do a second table and join ID’s together but it seems like a lot of work.

I have a person table, personID as the index.

I then have a car table with carID as index.

Some people will be assigned multiple cars. In the person tale can I store an array like 47,52,14 and then still join them to the cars table?

to post a comment

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 11.2021 — It _might_ be possible to make a join work that way, but I can't see how it could do it efficiently (i.e. leverage table indexes instead of doing full table reads). Personally, I'd just make the little 2-column join table (with a unique index across both columns if no car should ever be assigned to more than one person, otherwise just a regular index).
Copy linkTweet thisAlerts:
@kiwisauthorJan 11.2021 — @NogDog#1626641

Yeah I've always done it this way. Just wondered if there was a shorter quicker way
Copy linkTweet thisAlerts:
@NogDogJan 11.2021 — I suppose with the "right" framework that has built in database creation commands, it might just be a fairly simple set of a few commands to create that table and add "has_many" relationships to the other 2 tables. However, "simple" is complicated by the fact that you first have to learn how to do that in that particular framework -- along with everything else you have to learn about it to get it to work. 😐️
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...