Replace looping with a single query for INSERT / UPDATE
问题 I am writing a function in PostgreSQL. It does basically 3 steps: Fetch a record from source table. check the value from the fetched record in target table, if record is found in target table then update all values of target table with fetched record otherwise insert fetched record to target table. Instead of doing this looping, if I write single query for insert/update, will it be faster than above mentioned approach? How can I achieve same result by writing single query instead looping