Skip to main content
added 9 characters in body
Source Link
Erik Eidt
  • 34.8k
  • 6
  • 61
  • 95

Is storing a list of strings in single database field a bad idea?

It would generally be considered a violation of normalization.

However, sometimes this is used a solution to a problem, e.g. in hierarchical structuring, where a variable length path string of some sort represents structure.

Among the problems with a list of items in a single string can be:

  • in query, this means using string searches instead of relational calculus; indexing the data can be problematic.
  • there is the question as to the meaning of the ordering of the entries in the list, and that you more than likely cannot enforce anything on ordering as a constraint on the db.
  • there is the issue of separator character, and the potential for character escaping/un-escaping problem with the individual items.
  • there is the potential for duplicate entries in the same list; again this stems from not being able to directly enforce constraints (though maybe a trigger function could check constraints).
  • a single item alone is still a list, but might be mistaken as not since we cannot tell (or ask) the database that the true type is a list. This can be problematic if most rows have only one item in the list, when some have more than one: there's no way to enforce proper usage of the column as a list.

Is storing a list of strings in single database field a bad idea?

It would generally be considered a violation of normalization.

However, sometimes this is used a solution to a problem, e.g. in hierarchical structuring, where a variable length path string of some sort represents structure.

Among the problems with a list of items in a single string can be:

  • in query, this means using string searches instead of relational calculus; indexing the data can be problematic.
  • there is the question as to the meaning of the ordering of the entries in the list, and that you more than likely cannot enforce anything on ordering as a constraint on the db.
  • there is the issue of separator character, and the potential for character escaping/un-escaping problem with the individual items.
  • there is the potential for duplicate entries in the same list; again this stems from not being able to directly enforce constraints (though maybe a trigger function could check constraints).
  • a single item alone is still a list, but might be mistaken as not since we cannot tell the database that the true type is a list. This can be problematic if most rows have only one item in the list, when some have more than one: there's no way to enforce proper usage of the column as a list.

Is storing a list of strings in single database field a bad idea?

It would generally be considered a violation of normalization.

However, sometimes this is used a solution to a problem, e.g. in hierarchical structuring, where a variable length path string of some sort represents structure.

Among the problems with a list of items in a single string can be:

  • in query, this means using string searches instead of relational calculus; indexing the data can be problematic.
  • there is the question as to the meaning of the ordering of the entries in the list, and that you more than likely cannot enforce anything on ordering as a constraint on the db.
  • there is the issue of separator character, and the potential for character escaping/un-escaping problem with the individual items.
  • there is the potential for duplicate entries in the same list; again this stems from not being able to directly enforce constraints (though maybe a trigger function could check constraints).
  • a single item alone is still a list, but might be mistaken as not since we cannot tell (or ask) the database that the true type is a list. This can be problematic if most rows have only one item in the list, when some have more than one: there's no way to enforce proper usage of the column as a list.
Source Link
Erik Eidt
  • 34.8k
  • 6
  • 61
  • 95

Is storing a list of strings in single database field a bad idea?

It would generally be considered a violation of normalization.

However, sometimes this is used a solution to a problem, e.g. in hierarchical structuring, where a variable length path string of some sort represents structure.

Among the problems with a list of items in a single string can be:

  • in query, this means using string searches instead of relational calculus; indexing the data can be problematic.
  • there is the question as to the meaning of the ordering of the entries in the list, and that you more than likely cannot enforce anything on ordering as a constraint on the db.
  • there is the issue of separator character, and the potential for character escaping/un-escaping problem with the individual items.
  • there is the potential for duplicate entries in the same list; again this stems from not being able to directly enforce constraints (though maybe a trigger function could check constraints).
  • a single item alone is still a list, but might be mistaken as not since we cannot tell the database that the true type is a list. This can be problematic if most rows have only one item in the list, when some have more than one: there's no way to enforce proper usage of the column as a list.