3 ms·
I don't disagree things like this are pain points, but one of the key things about unlocking the power of relational algebra is having normalized data, and putt
by Amezarak 4y ago
I don't disagree things like this are pain points, but one of the key things about unlocking the power of relational algebra is having normalized data, and putting multiple things (eg a bunch of key value pairs) in a single value sort of flies in the face of that. You can often get away with it, but it starts breaking down in more complex cases like this.
In the real world of course, sometimes it happens anyway. Maybe you were storing URIs and only later figured out you needed to extract keys from them. But thinking about this sort of thing beforehand as much as possible can save you a lot of heartache later on.
That said, this fails the ISO SQL requirement (I believe), but I'd use the table-valued function STRING_SPLIT in MS SQL, then I can just filter on LIKE 'baz=%", and SELECT the substring after baz=. Table-valued functions are great. The nice thing about this solution is it's very easy to generalize.
I believe MySQL doesn't have a similar function, but you could do something with SUBSTRING and LOCATE - search for the first occurrence of baz=, then you can use that to find the first location of & after baz=, which will allow you to select the substring between baz= and &.