postgres 10.3
I have about 1000 rows inside a table called sites
If I query like this
SELECT id, name from sites;
I will get the 1000 rows.
I also have another table called jsonindexdocument with a single row where the id is 1 and a field called index that is JSONB
Is it possible that in a single query I take out all the 1000 rows in sites table and then update the field called index under id 1?
The format of the json would be
[
{
"id": 10,
"name": "somename"
},
{
"id": 11,
"name": "another name"
} // and the rest of the 1000 rows
]
I am also okay if it uses more than 1 raw SQL statement.
UPDATE
I want to add that if the result is empty set, then default to empty array in the json field