Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lS381-0003Wl-Sv for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 19:37:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lS37y-0001dh-EP for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 19:37:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lS37y-0001by-1n for pgsql-general@lists.postgresql.org; Thu, 01 Apr 2021 19:37:14 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lS37v-0000UA-AW for pgsql-general@lists.postgresql.org; Thu, 01 Apr 2021 19:37:13 +0000 Received: by mail-pj1-x1036.google.com with SMTP id x21-20020a17090a5315b029012c4a622e4aso1562692pjh.2 for ; Thu, 01 Apr 2021 12:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=acERg4vjkKHs1dtTLWfmU6vQYzsajUmI3iN99auc/FY=; b=ckSgz0BGPGBTrmxFTwj8wDldBjkvjLF4YoUetm/PW9/MPxPDCVFAyPGsxiJ+n58OGW vk2CFfRn34i/f5QddwjlgzgiBc9+7yitpNMyCwg0LUp9qgT80yM4ZLKPXxutQIiMnqbp jSDmMeDi/QRXvVp/Av0wwJBrU8XStRqC/ejIqtvfoeg7wFnBiUBW1EegSC36NFwKKWjT +BSUxS3zGy5PhPyxHfDr0oyrDmUgHN6N3+MQ8d/xjA//JCQqbSJveyiLbYzIojXFJ9Tw atYXI6LM3Aa8Uik2v1/yIp/FQ1ECnszhO3o/UL9DPWf40fPciah+4qZ2vEbtBfU0NFag N7UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=acERg4vjkKHs1dtTLWfmU6vQYzsajUmI3iN99auc/FY=; b=ZbnTJlsVusDW271GpdAGUoX3uTINIUBDvm2hILYxciKfDNxga1lhIt0KAUfo2n/dA6 4mxFHbU9kXZNaQ6xSjRdjLBLS0EUoKkjZjKopJRUEpvinE3nFFaQ3uhk1ZjzTFikI+VI ekljd2oY9GoZAUbSenHFq3JXI9SNlmKad2ZqTBGQ9IFpVcfF0xc+b0e9JnRmmU6T3tM/ Yl+UWpELXfv1K1CuiYRrWdmUcwM7JkbZkKzHe6A7loPz6plIpA/Re1GRxmD6gm5bzmkk 4d6qL/ayPt7wQDnlag7sSGFj5l0y280Ig3ap/nq28JKKrtQYV3EVC716JomPMl20Wdas qSpA== X-Gm-Message-State: AOAM530hr8ypSusZgjI8L5l8y8jZyx6UmyeDV7hyPteIFQQua/TK2/xZ yDtHEqG04gSXLFmrIxVzfjxvSE7Z4hXo/g== X-Google-Smtp-Source: ABdhPJyoaKLQnwmem2mwGPq6+WaXnI5/0GSxmeQiSo95jWRqtHfC2RFv9iZY7K+ogY+oXt2OpB62DQ== X-Received: by 2002:a17:90a:c20a:: with SMTP id e10mr9953296pjt.221.1617305828232; Thu, 01 Apr 2021 12:37:08 -0700 (PDT) Received: from [192.168.2.105] ([50.53.109.254]) by smtp.googlemail.com with ESMTPSA id 14sm6120864pfl.1.2021.04.01.12.37.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Apr 2021 12:37:07 -0700 (PDT) Subject: Re: Slick way to update multiple tables. To: pgsql-general@lists.postgresql.org References: From: Paul Jungwirth Message-ID: <2662957f-36c0-4e02-6be9-f7bf52729309@illuminatedcomputing.com> Date: Thu, 1 Apr 2021 12:37:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/1/21 11:54 AM, Michael Lewis wrote: > postgresql.org/docs/current/sql-createview.html > > > My apologies. It seems INSTEAD OF triggers are required to implement > updates across multiple tables. I thought not if all were simple joins. > My mistake. Even with INSTEAD OF triggers, if you use a view then I suppose you would be forced to update some of the records more often that necessary? (Unless your tables are 1-to-1-to-1 of course.) Or if there is some trick to avoid that I'd be curious to know about it. Here is something I've done in the past: WITH update1(ok) AS ( UPDATE foo SET ... WHERE ... RETURNING 'ok' ), update2(ok) AS ( UPDATE bar SET ... WHERE ... RETURNING 'ok' ), update3(ok) AS ( UPDATE baz SET ... WHERE ... RETURNING 'ok' ) SELECT ok FROM update1 UNION ALL SELECT ok FROM update2 UNION ALL SELECT ok FROM update3 ; You could even select different messages from each update if you want to know how many rows you touched in each table. -- Paul ~{:-) pj@illuminatedcomputing.com