In MSSQL when inside a multi-statement table valued function you can interact w/ the table as shown below.
CREATE FUNCTION dbo.test_func() RETURNS @table TABLE(id INT) AS
BEGIN
INSERT INTO @table(id)
SELECT 1 UNION SELECT 2 UNION SELECT 3
UPDATE @table SET id = -1 WHERE id = 3
RETURN
END
GO
Is there a way to accomplish this in Postgres 9.5? I'm not sure what to update as shown below.
CREATE FUNCTION test_func() RETURNS TABLE(id int) AS $$
BEGIN
return QUERY SELECT 1 UNION SELECT 2 UNION SELECT 3;
UPDATE ???? SET id = -1 WHERE id = 3;
END;
$$ LANGUAGE plpgsql STABLE;
@tableidentifier with a proper table name (the insert can actually be written a lot shorter using thevaluesclause). But what does the singlereturndo at the end? What does it return?@tableidentifier". What would I replace it with in Postgres? I know INSERT would turn into RETURN QUERY.