Mateusz
Mateusz

Reputation: 171

Selecting a row from a table that matches pattern

I'm trying to select a specific row that matches a pattern through bash. But something is not working and I get empty output (0 record(s) selected.). Code looks like that:

su --login root -c "db2 connect to TILT; db2 \"select * from TABLE1 where COLUMN4 like '%\"selections\":[{\"college\":[\"9\",\"28\",\"29\",\"34\",\"35\",\"37\",\"48\",\"54\",\"55\",\"67\"]%'\""

The row from column4 that I'm trying to access looks like this:

,{"changelog":1},"selections":[{"college":["9","28","29","34","35","37","48","54","55","67"]

What am I missing? Any help appreciated. Thanks

Upvotes: 0

Views: 144

Answers (1)

Pavol Adam
Pavol Adam

Reputation: 162

You escape the quotes for DB2 argument, but inside them, quotes should be escaped, too, to distinguish them from the end quotes for the db2 argument. Also escaping the already escaped quotes: \\\"

So instead e.g.

... '%\"selections\": ...

You should write

... '%\\\"selections\\\": ...

Upvotes: 1

Related Questions