Skip to content
Advertisement

User function return query and insert into

I trying to make function, that merge where select query return result as value(not table) and insert into that use value from select statement.
The function where argument gets from user, and this argument provide into select query on table_foo that return value id where I try set and use in insert into to diff table(table_bar). So I little bit confused. Here sample of code:

Advertisement

Answer

No need for plpgsql and no need for two queries either. Combine the INSERT and SELECT, and use RETURNING.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement