Products store their variable attributes as a JSON blob in a single TEXT
column, rather than one column per possible attribute.
Table: `products`
| id | name | attrs |
|---|---|---|
| 1 | Widget | {"color":"red","price":19.99} |
| 2 | Gadget | {"color":"blue","price":29.99} |
Write a query that returns each product's id, name, and thecolor pulled out of attrs.
Expected output (columns: id, name, color), ordered by id:
1|Widget|red
2|Gadget|blueHint — SQLite's JSON functions use
$.fieldpath syntax:
json_extract(attrs, '$.color'). (SQLite 3.27, which this platform runs,predates the
->/->>operator syntax — that needs 3.38+ — so
json_extract()is the only option here.)
Sample tests