updating table rows in postgres using subquery

前端 未结 6 1183
北荒
北荒 2020-11-27 08:42

Using postgres 8.4, My goal is to update existing table:

CREATE TABLE public.dummy
(
  address_id SERIAL,
  addr1 character(40),
  addr2 character(40),
  ci         


        
6条回答
  •  [愿得一人]
    2020-11-27 09:29

    You're after the UPDATE FROM syntax.

    UPDATE 
      table T1  
    SET 
      column1 = T2.column1 
    FROM 
      table T2 
      INNER JOIN table T3 USING (column2) 
    WHERE 
      T1.column2 = T2.column2;
    

    References

    • Code sample here: GROUP BY in UPDATE FROM clause
    • And here
    • Formal Syntax Specification

提交回复
热议问题