I want to turn jsonb values into a key-value table within a single statement
My sample code:
CREATE TABLE public.searchdatacache
( querysig text, "values" jsonb );
INSERT INTO searchdatacache (querysig, values)
VALUES
(
'ytApiSearch://Armageddon trailer',
'[
{"VideoId" : "xwseawq"},
{"Title" : "Armageddon"},
{"PublishedAt" : "2012/01/01"},
{"Description" : "Armageddon is a film"},
{"ChannelTitle" : "Bruce Willis Movies"}
]'
)
SELECT jsonb_array_elements(values) from searchdatacache where querysig = 'ytApiSearch://Armageddon trailer'
returns:
"{"VideoId": "xwseawq"}"
"{"Title": "Armageddon"}"
"{"PublishedAt": "2012/01/01"}"
"{"Description": "Armageddon is a film"}"
"{"ChannelTitle": "Bruce Willis Movies"}"
the data returned by the select statement looks ok so far but now I want to use this select statement within an "INSERT INTO" statement to fill a key-value table.
these records should be filled into a new key-value table:
VideoId | xwseawq
Title | Armageddon
PublishedAt | 2012/01/01
Description | Armageddon is a film
ChannelTitle | Bruce Willis Movies
thanks in advance Gerald