Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efFGt-0004QO-Ri for pgsql-general@arkaria.postgresql.org; Sat, 27 Jan 2018 01:27:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efFGr-00052v-Ua for pgsql-general@arkaria.postgresql.org; Sat, 27 Jan 2018 01:27:05 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1efFGr-00052l-Cb for pgsql-general@lists.postgresql.org; Sat, 27 Jan 2018 01:27:05 +0000 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1efFGn-0000tY-Sx for pgsql-general@postgresql.org; Sat, 27 Jan 2018 01:27:03 +0000 Received: by mail-wr0-x232.google.com with SMTP id s5so1988829wra.0 for ; Fri, 26 Jan 2018 17:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:organization:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=pkcRQD8M9aakjZ/menUs7sdN84vB27jpCMvfF5wez1w=; b=NlnBZaa/hMjc/2zJHZ0XpDJtio5zrHOKoANM2meH1iqOScDg3FcNg/eGsOANHkjzwE 1SVxl43wH6zNKLTNb5YXLlO6BL/4qgZjdWNqzsKI3hmFV34bpRE+O8rD1MVc3dH7BNtX j8ubfLMYFnb3zS6V7kW9lTSSkYucSOrwGuWB/Y9Ve/1v8SCAJvZZA42ZG7sVf01X6q5A LH5hGx3hpH2W0slO4nruQjgefGD2uT12/tQwFDAlCBLUjN/BEJYqrjMFk+yGIZ32lyry fiY7fTcG6PXskpMyyMN9bq5s6zUXNILXUJ1FG6UmBZHcUxvKXKQtBNzzn685CjwyQhlZ 6AAA== 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:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=pkcRQD8M9aakjZ/menUs7sdN84vB27jpCMvfF5wez1w=; b=KvobV0YEdjxJBohPSqo04StivyIEsPkItsvGK5CjjXznVhipL+rN3gpQe6JEahCUIz 5GQv0obCOJDKKjPQfYPzHxH1TB+JFKErfDsjfqN4SF1YOsbNzGubcxj5pg3ying6ZOft QpDv/QS6qBYPp50K0ZkCAXyiTv6Z4PlnM/gxXmA0c5W0c2ali3muFi4giXCRq1/LUBgi I4Qi6sWRu4xvsbqpBMiDR3igSqVElSaOsRVqUOjX0sKJG0TJjkKaQzMvqPSffI3GTTm8 4+4FrCuxEno9rrrJPqcB+8SCGSm4XLPLzEl83uO7FinDMg1XHtN5MUZFhtlS/QknA06x yIPw== X-Gm-Message-State: AKwxytca5qWIQxycqWuXd9Q/4y/yPrAAB12pTTmr0rFC0qlmfstCzQio RDJflX4Z/wFM1Lbr0BN06Pm1WdOOCgM++m28hVGcHLyZcnqr+MOUi3qLqC7xd+GVsOPQ9ZKU7vv T+MqDSpEN8vUJnXt0b20+R9hM2goswpg052DaJSCvMGONcuQUBGRyaVyN789JXhIZGlkSA2ppuo rxYLn4c3yHRQ== X-Google-Smtp-Source: AH8x226Eh7ZhIHaecXAVCqizj6FiOI7YOy5GE0doyQQYbPiV0X1W4hbkfFznnu4QVxqHIV/aPy46GA== X-Received: by 10.223.141.211 with SMTP id o77mr3467147wrb.39.1517016417995; Fri, 26 Jan 2018 17:26:57 -0800 (PST) Received: from [192.168.0.3] (ath91-3-88-167-161-184.fbx.proxad.net. [88.167.161.184]) by smtp.gmail.com with ESMTPSA id m86sm6604596wmi.40.2018.01.26.17.26.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 17:26:57 -0800 (PST) Subject: Re: A little RULE help? To: Steven Winfield , "pgsql-general@postgresql.org" References: From: Vik Fearing Organization: 2ndQuadrant France Message-ID: <4e9b5b67-8966-4dfb-dcf9-6023c3b8fff1@2ndquadrant.com> Date: Sat, 27 Jan 2018 02:26:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/26/2018 04:19 PM, Steven Winfield wrote: > Back to my original attempt at writing an UPDATE rule… > > CREATE RULE rule_test_update AS ON UPDATE TO rule_test_view DO INSTEAD ( > >         UPDATE rule_test SET tt = tstzrange(lower(tt), > CURRENT_TIMESTAMP, '[)') WHERE id = OLD.id; > >         INSERT INTO rule_test (tt, foo, bar) VALUES > (tstzrange(CURRENT_TIMESTAMP, NULL, '[)'), NEW.foo, NEW.bar) RETURNING *; > > ); > > …I wondered whether the pseudo relations NEW and OLD were somehow being > modified by the first command (the UPDATE), such that the second command > (INSERT) could not function properly. No. It's because your view's WHERE clause is being added to your INSERT and of course nothing matches, so nothing gets inserted. > That would fit with what I observe, but I’m not sure how I go about > proving EXPLAIN > or fixing it. Don't use RULEs. -- Vik Fearing +33 6 46 75 15 36 http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support