Hello when I run the below query:
SELECT fundid
FROM funds
WHERE reportingfrequency = 'Daily'
AND primarynavcostlocation = 'Wroclaw'
AND primaryaccountmgr1 = 'wx
I get:
"fundid"
11111
22222
So now what I'm trying to do is insert both those fundid rows along with an array so that the data will look something like below:
"fundid" | "listdate"
11111 | {2021-01-02, 2021-01-03}
22222 | {2021-01-02, 2021-01-03}
I've tried to finagle the query's around to get an insert working such as -
INSERT into nav_due_dates (fund_id, listdate)
VALUES(
(
SELECT fundid
FROM funds
WHERE reportingfrequency = 'Daily'
AND primarynavcostlocation = 'Wroclaw'
AND primaryaccountmgr1 = 'wxy'
),
(
SELECT array_agg(weekdays::date)
FROM generate_series(date'2021-01-01', date'2021-12-31', interval '1' day) as t(weekdays)
LEFT JOIN holidays.poland(2021, 2021) f ON (weekdays = f.datestamp)
WHERE f.datestamp IS NULL
AND extract(dow from weekdays) BETWEEN 1 AND 5
)
);
It returns:
ERROR: more than one row returned by a subquery used as an expression
and I've also tried the following after doing some digging -
INSERT INTO nav_due_dates (fund_id, listdate)
SELECT fundid
WHERE reportingfrequency = 'Daily'
AND primarynavcostlocation = 'Wroclaw'
AND primaryaccountmgr1 = 'wxy',
(
SELECT array_agg(weekdays::date)
FROM generate_series(date'2021-01-01', date'2021-12-31', interval '1' day) as t(weekdays)
LEFT JOIN holidays.poland(2021, 2021) f ON (weekdays = f.datestamp)
WHERE f.datestamp IS NULL
AND extract(dow from weekdays) BETWEEN 1 AND 5
)
FROM funds;
But the syntax errors I can't seem to resolve such as removing the , or the parenthesis around the array select statement that populates the listdate column.