use select in with block and update with join back in order to retain lateral joins in the update
This commit is contained in:
parent
43f9bb2d10
commit
87407e36fc
@ -1,26 +1,9 @@
|
|||||||
UPDATE
|
WITH
|
||||||
tps.srce
|
mod AS (
|
||||||
SET
|
|
||||||
defn =
|
|
||||||
--delete "schemas" from existing json and tack on revamped layout
|
|
||||||
jsonb_pretty((defn - 'schemas')||
|
|
||||||
--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)
|
|
||||||
)
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
---------------select statement test-----------------------
|
|
||||||
/*
|
|
||||||
SELECT
|
SELECT
|
||||||
srce
|
srce
|
||||||
,jsonb_pretty(defn)
|
,jsonb_pretty(defn) orig
|
||||||
,jsonb_pretty((defn - 'schemas')||
|
,(defn - 'schemas')||
|
||||||
--rebuild the schemas key value from below
|
--rebuild the schemas key value from below
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'schemas'
|
'schemas'
|
||||||
@ -29,11 +12,19 @@ SELECT
|
|||||||
--combine a new key 'name' with the columns for that name
|
--combine a new key 'name' with the columns for that name
|
||||||
jsonb_build_object('name',k)||jsonb_build_object('columns',v)
|
jsonb_build_object('name',k)||jsonb_build_object('columns',v)
|
||||||
)
|
)
|
||||||
))
|
) rebuild
|
||||||
FROM
|
FROM
|
||||||
tps.srce
|
tps.srce
|
||||||
LEFT JOIN LATERAL jsonb_each(defn->'schemas') WITH ORDINALITY je(k,v, rn) ON TRUE
|
LEFT JOIN LATERAL jsonb_each(defn->'schemas') WITH ORDINALITY je(k,v, rn) ON TRUE
|
||||||
GROUP BY
|
GROUP BY
|
||||||
srce
|
srce
|
||||||
,defn
|
,defn
|
||||||
*/
|
)
|
||||||
|
UPDATE
|
||||||
|
tps.srce s
|
||||||
|
SET
|
||||||
|
defn = rebuild
|
||||||
|
FROM
|
||||||
|
mod
|
||||||
|
WHERE
|
||||||
|
mod.srce = s.srce
|
Loading…
Reference in New Issue
Block a user