Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r3t30-006L0E-Kp for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Nov 2023 07:13:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r3t1z-00CIVB-2w for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Nov 2023 07:12:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r3t1y-00CIV3-Mo for pgsql-hackers@lists.postgresql.org; Fri, 17 Nov 2023 07:12:46 +0000 Received: from mail-ua1-x92e.google.com ([2607:f8b0:4864:20::92e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r3t1w-006raq-A4 for pgsql-hackers@lists.postgresql.org; Fri, 17 Nov 2023 07:12:46 +0000 Received: by mail-ua1-x92e.google.com with SMTP id a1e0cc1a2514c-7b9c8706fc1so625683241.0 for ; Thu, 16 Nov 2023 23:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700205162; x=1700809962; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0F+r6pXs9bk8X4KSZc4h24IlXnQW2ro1oRWFzu7i8IA=; b=fqbEuo+LMoZ7fiOA0mSOt3Orx0gGc9O1tpAIGVhn0PA/YbH6YlVYLUNIxhDHDsPWwV +koiRZg874Jrnkxuh8d6tcIgRmBe4OFDYri2pTr+oKlZKpw18GohBfQsJmlIG+lX0oxx 3QwmLj+58TvDyYp45dadi+dmk8ouHXd6NwHqacB7kG9Kvc4fD7q2nrYHwMI8727GIr8Y C+X2GR57O/5zruuxItCrhYa0Sk1aB3iuD2rA461vYllfTe/eMALdUzsxVfVOX9OdhISM QDn2e8hFZV6P3wGJY3p2xAwn0MX9hVOuZAJv4J4B0fb3yj88lx2hgzw1J4mCVt+qvUdY qJfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700205162; x=1700809962; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0F+r6pXs9bk8X4KSZc4h24IlXnQW2ro1oRWFzu7i8IA=; b=PNFlmVkpCAoimQLHbKyeuJ1u8zbghUKDEvK/fA04ery6cjCtH5wC7RtkWRcTdkq0fA +DRikLQOjJ8xV1vGbR5ycvUoeCB7I1mdCrD96NDMb0OXv+2w02BCTwYeZOhihg+mIZTg yxUuMcCuXRHk9gNVR2ySwcf7tvWs12w+CItUvhF8e0FkBxtMn5+Jv2NNmnTHHzPtWOcj HOc6QS+rDKaLViYbgL+mWc3b49vJgbxJ1mgXucZx1eXyKzUgvCqU9cHo2cffRs1sgjo1 nBxv8kNmwK+eEKfMIaxke/Umw/NcrCj3phOa1p5nbDmwmfx3L6gOBnhvbc1Pp8OP+xyR ZvoQ== X-Gm-Message-State: AOJu0YznQ4U1aitl5j3sZwfBR41tJ2F6wtVQXLnCX5mZq8u9YZW4ONBP RcQqadYdztX36K8gPWJRuYvFohBiq7zFUACGGow= X-Google-Smtp-Source: AGHT+IFWMeh4gaEPU4EnzYgLuFv/Ru66sTOAGtgzOiZuKYe1q3KnEHyXhSf5jPj19wM+hQoqnG/zTjtIlD4Tv0w1p1g= X-Received: by 2002:a05:6122:a19:b0:4ab:ef58:fca4 with SMTP id 25-20020a0561220a1900b004abef58fca4mr21201299vkn.7.1700205162282; Thu, 16 Nov 2023 23:12:42 -0800 (PST) MIME-Version: 1.0 References: <5157e85a-6007-27a7-853a-5601d9c3722f@illuminatedcomputing.com> <5a16a59a-d497-7d72-07aa-0afc09d5193a@illuminatedcomputing.com> <2d9740ad-3bb7-473c-8441-344351caa8ee@illuminatedcomputing.com> In-Reply-To: From: jian he Date: Fri, 17 Nov 2023 15:12:30 +0800 Message-ID: Subject: Re: SQL:2011 application time To: Paul Jungwirth Cc: Peter Eisentraut , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk based on v17. begin; drop table if exists s1; CREATE TABLE s1 (id numrange, misc int, misc1 text); create role test101 login; grant update, select on s1 to test101; insert into s1 VALUES ('[1,1000]',2); set session authorization test101; update s1 set id = '[1,1000]'; savepoint sp1; update s1 FOR PORTION OF id from 10 to 100 set misc1 = 'test'; table s1; savepoint sp2; insert into s1 VALUES ('[2,1000]',12); rollback; In UPDATE FOR PORTION OF from x to y, if range [x,y) overlaps with the "source" range then the UPDATE action would be UPDATE and INSERT. The above UPDATE FOR PORTION OF query should fail? UPDATE FOR PORTION OF, may need insert privilege. We also need to document this. Similarly, we also need to apply the above logic to DELETE FOR PORTION OF. ------------------------------------------------------- + + If the table has a range column + or PERIOD, you may supply a should be + + If the table has a range column or + PERIOD, you may supply a similarly the doc/src/sgml/ref/delete.sgml the link reference also broken. -------------------------------------------------------- If the table has a range column or PERIOD, you may supply a FOR PORTION OF clause, and your update will only affect rows that overlap the given interval. Furthermore, if a row's span extends outside the FOR PORTION OF bounds, then it will be truncated to fit within the bounds, and new rows spanning the "cut off" duration will be inserted to preserve the old values. "given interval", "cut off" these words, imho, feel not so clear. We also need a document that: "UPDATE FOR PORTION OF" is UPDATE and INSERT (if overlaps). If the "UPDATE FOR PORTION OF" range overlaps then It will invoke triggers in the following order: before row update, before row insert, after row insert. after row update. --------------------------------------- src/test/regress/sql/for_portion_of.sql You only need to create two triggers? since for_portion_of_trigger only raises notice to output the triggers meta info. CREATE TRIGGER trg_for_portion_of_before BEFORE INSERT OR UPDATE OR DELETE ON for_portion_of_test FOR EACH ROW EXECUTE FUNCTION for_portion_of_trigger(); CREATE TRIGGER trg_for_portion_of_after AFTER INSERT OR UPDATE OR DELETE ON for_portion_of_test FOR EACH ROW EXECUTE FUNCTION for_portion_of_trigger();