penguin-penpen penguin-penpen - 5 months ago 8x
SQL Question

mysql - How to determine the length of a field which stores a mutable string?

I'm working on a iOS application and I use Flask(a Python framework) to build my backend.

I store my data in


Now I need to store a bunch of IDs in one attribute.

Firstly I convert the array which stores the IDs to a
format object.

Then I ran into a problem. How to store this object?

As the length of the object can be rather large(I cannot make sure how many IDs I store), and
requires the attribute to have a exact length when I create the table, so how to determine the length of the attribute?


I don't quiet know the situation you meet , But it's not recommended to store multi records in one column , It's more normalised to build a relation map between ID owner and ID .

For example , you can create a new table called 'IDs' with schema like that :

id int auto increment ,
idbla varchar(<Your ID Length>)
owner int not null

When you are trying to get all idbla of some user x you can use

SELECT * idbla from IDs where owner = x

Another choice :

You can use nosql (non relational database) to store your data , It's document like and fit your situation pretty well .