The same basic execution logic is used to handle all four of the basic SQL query types: SELECT, INSERT, UPDATE, and DELETE. For example, when doing an UPDATE, the identified rows to update are found in a familiar way and then fed to an Update node:
EXPLAIN ANALYZE UPDATE customers SET state=state WHERE customerid=1; QUERY PLAN ---------- Update (cost=0.00..0.28 rows=1 width=274) (actual time=63.289..63.289 rows=0 loops=1) -> Index Scan using customers_pkey on customers (cost=0.00..0.28 rows=1 width=274) (actual time=0.054..0.063 rows=1 loop s=1) Index Cond: (customerid = 1) Total runtime: 63.415 ms
UPDATE and DELETE can execute efficiently by keeping track of the tuple ID uniquely identifying each of the rows they are then called to operate on. Note that the preceding UPDATE doesn't actually...