2018-12-02 01:18:29 -05:00
|
|
|
WITH
|
|
|
|
mod AS (
|
2018-12-02 00:59:00 -05:00
|
|
|
SELECT
|
|
|
|
srce
|
2018-12-02 01:18:29 -05:00
|
|
|
,jsonb_pretty(defn) orig
|
|
|
|
,(defn - 'schemas')||
|
2018-12-02 00:59:00 -05:00
|
|
|
--rebuild the schemas key value from below
|
|
|
|
jsonb_build_object(
|
|
|
|
'schemas'
|
|
|
|
--aggregate all the new key values for a single soure
|
|
|
|
,jsonb_agg(
|
|
|
|
--combine a new key 'name' with the columns for that name
|
|
|
|
jsonb_build_object('name',k)||jsonb_build_object('columns',v)
|
|
|
|
)
|
2018-12-02 01:18:29 -05:00
|
|
|
) rebuild
|
2018-12-02 00:59:00 -05:00
|
|
|
FROM
|
|
|
|
tps.srce
|
|
|
|
LEFT JOIN LATERAL jsonb_each(defn->'schemas') WITH ORDINALITY je(k,v, rn) ON TRUE
|
|
|
|
GROUP BY
|
|
|
|
srce
|
2018-12-02 01:01:19 -05:00
|
|
|
,defn
|
2018-12-02 01:18:29 -05:00
|
|
|
)
|
|
|
|
UPDATE
|
|
|
|
tps.srce s
|
|
|
|
SET
|
|
|
|
defn = rebuild
|
|
|
|
FROM
|
|
|
|
mod
|
|
|
|
WHERE
|
|
|
|
mod.srce = s.srce
|