I am trying to get all the photo urls into an array and set that array to be a new column in a different table. The tables have a one to many relationship. I have about 1 million rows on my list_reviews table and around 3 million photos.
Is there a way to do this in batches? When I tried to do it all in one shot I just got empty arrays.
https://www.postgresql.org/message-id/20051219121211.002f7e87.gry@ll.mit.edu and Postgresql select rows(a result) as array
Those work if I am only doing one at a time. I have been thinking about trying to use the STREAMING found here, https://github.com/vitaly-t/pg-promise/wiki/Learn-by-Example#into-database but not sure I totally understand what is going on here.
CREATE TABLE list_reviews (
id SERIAL PRIMARY KEY,
product_id INT,
photos TEXT[]);
CREATE TABLE review_photos (
id SERIAL,
review_id INT REFERENCES list_reviews(id) ON DELETE CASCADE,
url TEXT);
UPDATE list_reviews SET photos = array(
SELECT url
FROM review_photos
WHERE review_photos.id = list_reviews.id
AND list_reviews.id = 5);
list_reviews looks like:
+----+------------+--------+--+
| id | product_id | photos | |
+----+------------+--------+--+
| 5 | 1 | [] | |
+----+------------+--------+--+
review_photos looks like:
+----+-----------+------------+--+
| id | review_id | photos | |
+----+-----------+------------+--+
| 1 | 5 | something1 | |
| 2 | 5 | something2 | |
| 3 | 5 | something3 | |
+----+-----------+------------+--+
and would expect to see list_reviews:
+----+------------+--------------------------------------+--+
| id | product_id | photos | |
+----+------------+--------------------------------------+--+
| 5 | 1 | [something1, something2, something3] | |
+----+------------+--------------------------------------+--+