I have a table called sports as below
I need to append another day's details into the table for red team like below
Note: Without unnesting the existing record, just a simple append. Is there any way to get this done?
I am assuming that the column in question is an ARRAY<STRUCT>? Within a table, you can append new rows or you can update existing rows. For your puzzle, you can either delete the old row and append a new row containing your desired new data ... OR ... you can update the existing row providing the new value for the column you want changed. Since the value of the new column/cell is an ARRAY<STRUCT> then you must supply a new ARRAY<STRUCT>.
It would be something like:
UPDATE sports
SET details = ARRAY(UNNEST(details), (newDate, newScore))
WHERE team = red
I did see you asked "without unnesting the original record". One way me might be able to achieve that is by leveraging the ARRAY_CONCAT function. This takes two or more arrays and returns a new array that is the concatenation of the two. A possibility for the SQL might then be:
UPDATE sports
SET details = ARRAY_CONCAT(details, [(newDate, newScore)])
WHERE team = red
For this to work, we need to convert the new value you wish to append to the existing array to an array itself.