On Sun, Dec 4, 2022 at 9:00 PM Peifeng Qiu <pgsql(at)qiupf(dot)dev> wrote:
> > the need for this code seems not that great. But as to the code itself
> I'm unable to properly judge.
> A simplified version of my use case is like this:
> CREATE FOREIGN TABLE ft(rawdata json);
> INSERT INTO tbl SELECT (convert_func(rawdata)).* FROM ft;
>
>
Which is properly written as the following, using lateral, which also
avoids the problem you describe:
INSERT INTO tbl
SELECT func_call.*
FROM ft
JOIN LATERAL convert_func(ft.rawdata) AS func_call ON true;
David J.