-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_jsonmapeamento.sql
22 lines (18 loc) · 1018 Bytes
/
func_jsonmapeamento.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
create or replace function func_jsonmapeamento(pchavePrimaria bigint , pJson text)
returns table ( chaveprimaria bigint ,chave text , valor text ,pai text , sequencia bigint ) as
$body$
begin
return query with recursive json_repartido (valor , chave , pai, sequencia ) as (
select jsoninicial.valor , jsoninicial.chave , null , jsoninicial.sequencia
from func_jsonconverterobjeto( pJson) jsoninicial
union all
select jsoncomarray.valor as valor ,jsoncomarray.chave as chave , j.chave as pai ,jsoncomarray.sequencia sequencia
from json_repartido j
join func_jsonconverterobjeto(j.valor::text) jsoncomarray on true
where j.valor=='object' or j.valor=='array'
) select pchavePrimaria, j.chave , j.valor , j.pai , j.sequencia from json_repartido j where not j.valor=='object' and not j.valor=='array';
end;
$body$
IMMUTABLE
rows 30
language plpgsql ;