Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you're talking about is a very unfortunate design pattern called serialization: that is, condensing multiple semantically different pieces of data into a single string. It's a bad idea most of the time, and in virtually all cases it's a better idea to separate your data into multiple fields, or even multiple tables. By using serialized fields, you'll find you:</p> <ul> <li>Have much, MUCH slower queries when querying multiple, serialized subfields</li> <li>Complicated queries for updating multiple parts of the same field</li> <li>Feelings of depression and despair</li> </ul> <p>If I had to deal with a database like that, and I couldn't alter the database structure, I'd probably end up doing a lot of the heavy lifting in program code. Many languages have better (or at least, more intuitive) string handling tools than SQL, and your performance benefits from using a RDBMS are going to be marginal at best when dealing with serialization anyway.</p> <p>But if you absolutely must do this in SQL, you should read through Postgres's string handling, located here: <a href="http://www.postgresql.org/docs/9.1/static/functions-string.html" rel="nofollow">http://www.postgresql.org/docs/9.1/static/functions-string.html</a></p> <p>And you're right, your solution is probably going to involve a regex. Exactly what that regex will look like depends on how many serialized fields it has to parse, and exactly how it's delimited. In your example, it looks like each subfield is delimited by a pair of spaces and a pipe character between them, and if that's the case make sure that you either create rules to let you escape that delimiter as needed, or make sure that the frontend never passes the delimeter to the database.</p> <p>Of course, if you have that kind of control over the frontend app, you could give the serialized data its own fields.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload