I have two table, with different columns, and I have to create a function to update the second table with the information from the first when the columns year match with the given year and group all in gender groups.
Here I put my code but I don't know if it is okay because the pgAdmin4 returns me an error because of the $$ symbols, although I am trying to solve it.
BEGIN WORK;
CREATE OR REPLACE FUNCTION update_report(p_year INTEGER)
RETURNS SETOF report1 AS $$
DECLARE report report1;
BEGIN
UPDATE report1 SET m.num=t_num, m.na=t_na, m.nd=t_nd, m.birth=t_birth
FROM report2 m
FULL JOIN report1
ON p_year= m.year
GROUP BY m.gender);
--In case there are any film in the specified year
IF NOT FOUND THEN
RAISE EXCEPTION ‘’%: No film exists in this year’’, -746;
END IF;
RETURN report;
END;
$$ LANGUAGE plpgsql;
COMMIT WORK;
Can someone just tell if it is okay? Thanks
group bywithout any aggregates is most definitely wrong. And you have a stray)after it. that's the obvious syntax errors I can see