0

I've a column that contain json values like

[
  {
    "name": "enabled",
    "value": "true",
    "type": "boolean"
  },
  {
    "name": "limit_amount_per_day",
    "value": "100",
    "type": "text",
    "pattern": "^[0-9]*$",
    "min": "0",
    "max": "100000"
  },
  {
    "name": "limit_amount_per_month",
    "value": "1000",
    "type": "text",
    "pattern": "^[0-9]*$",
    "min": "0",
    "max": "100000"
  },
]

or can be in

[{"name": "enabled", "value": "true", "type": "boolean"}, {"name": "limit_amount_per_day", "value": "100", "type": "text", "pattern": "^[0-9]*$", "min": "0", "max": "100000"}, {"name": "limit_amount_per_month", "value": "1000", "type": "text", "pattern": "^[0-9]*$", "min": "0", "max": "100000"},]

How can I query inside column in sql ?

For example... from that json , i want to get value that contains name 'enabled' so i could use it in another queries.

What i've tried was SELECT * FROM SOME_TABLE where value LIKE '%"name":"enabled", "value": "boolean"%' but it is very error prone .

Anybody can find out way with this?

1

1 Answer 1

1

Using json_table:

select k.value from test t 
cross join json_table(t.js, '$[*]' columns (name text path '$.name', value 
    text path '$.value')) k
where k.name = 'enabled'

See fiddle

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.