Skip to content

Parsing JSON in MariaDB with SQLPage #146

Answered by lovasoa
julesbouton asked this question in Q&A
Discussion options

You must be logged in to vote

Hello and welcome to SQLPage !

I added an example to the documentation which hopefully illustrates your use case: https://github.com/lovasoa/SQLpage/tree/main/examples/mysql%20json%20handling

insert into group_members(group_id, user_id)
select CAST(json_unquote(json_elems.json_value) AS INT), last_insert_id()
from (
    with recursive json_elems(n, json_value) as (
        select 0, json_extract(:Memberships, '$[0]')
        union all
        select n + 1, json_extract(:Memberships, concat('$[', n + 1, ']'))
        from json_elems
        where json_value is not null
    ) select * from json_elems where json_value is not null
) as json_elems
where :Memberships is not null;

Let me know if…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@julesbouton
Comment options

Answer selected by julesbouton
Comment options

You must be logged in to vote
1 reply
@julesbouton
Comment options

Comment options

You must be logged in to vote
2 replies
@julesbouton
Comment options

@lovasoa
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants