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.96) (envelope-from ) id 1wBTqT-0016RV-2u for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Apr 2026 08:37:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wBTqQ-00G9tI-2g for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Apr 2026 08:37:35 +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.96) (envelope-from ) id 1wBTqQ-00G9tA-1l for pgsql-hackers@lists.postgresql.org; Sat, 11 Apr 2026 08:37:35 +0000 Received: from mail-vs1-xe30.google.com ([2607:f8b0:4864:20::e30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wBTqO-00000000USl-2GBo for pgsql-hackers@lists.postgresql.org; Sat, 11 Apr 2026 08:37:34 +0000 Received: by mail-vs1-xe30.google.com with SMTP id ada2fe7eead31-605def5b800so1807130137.0 for ; Sat, 11 Apr 2026 01:37:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775896648; cv=none; d=google.com; s=arc-20240605; b=P65PgSwlWuAzdoRZn4z8xwOM/+FK6mbmW+nByz21yr6JlYxTccYy+prqzH1EB0HABR ZLINeSiOLOe3PSsU2sRF621O/b+R070nYU2cH49EfPgaJ4FMFrwPjO1KFSg+iqU/PbiY I83EfVz2gAfAEfSITaN0kca3oCLTKpS2ZmaoiPIe6P9TqQpCxq4NWeOEzHAdr2dJ9ekl 8o1NyasLhyUPjLajLvzfHw4TzYIO6R7YSA5taqLBjkNkhJwdAyTQ4GHCKGHn1DvpyEGR x3Fxq5PvHIXq2gBU5NYoF4TR+W8SoheXIdLet434dxQmZH9wvZIaOXjRYe8+ZMfyJSu0 pvbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uWBsq2qYCjY0fB0auP6pTxutNci+77Oltop9WS+uQAY=; fh=PDhzRmLFhJQgKl2kpY6iqaoiggk+rKjB8rXL7ERgOws=; b=MRAcIcFQdhkKT5kk0A316AlFeFqNOIJ3mJqxCYFSy8+6qHi4Hm207KRATFjqDv6glG UvseD8KZRqpS0SxWxpBIkhv4pFZvXZqHQOLdjQSfc2hLEJjG+rDlREw1+3i+sUVwh99x eR/w9sdZNgCyzg5B5AufPY8jQdrhvcJd4rkw8MdSABRcwdBlsRGDXQOIFrGZmF3iudRy NlPb9QwX8M6ydbcUbBkA9tzpPBze0H08Xr9HqPtv2BypUBGFye4/zv1Zymi2PprUC7b5 kYuGh8gKsLmC3sbKCtvQAJsXST4Tct0gRJ74sb9he4IMo28EKegrCHBmN9vfGT7KCWKX vYCw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775896648; x=1776501448; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uWBsq2qYCjY0fB0auP6pTxutNci+77Oltop9WS+uQAY=; b=JSvsOPxMvCjZbrOBPr0NJ9PzXLLwbcndDQ1E4TUF8/BK/WDzhFLo18uOUxFn5+8wDn rh2FUQU3rQx6cqZNVQQWnJw05Zyvl8KdejThMagE9ZYpBCT+vugo0FK8HWwH3tyMWk7H IBW1o7LSNsSm1aNt+ZcGDhpFcAsRn4HP9Hvi2Np5E2xd8tcjOpkhcY364y8Mtkt4drIf 11VJQue1VopYa52WPodfwanytIIbXhv5/eMhfA+UxkMkkP+xOz2QglBcQc65PtOcxlQ+ z/dnifha5cqjFErXEcfp/wEdNNrLrKZ1pDUII3T+vR+fgEsZh+/b62DjBkjgth2C7IHS vb+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775896648; x=1776501448; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uWBsq2qYCjY0fB0auP6pTxutNci+77Oltop9WS+uQAY=; b=hMPihIHs1pQXasCZbymyb1tfjz6f8zUsCT9qJG3u+VfTY3r1Sa6JqbkiP7zMnANM5A ydi5/RKB4Dpccb9ecGnXTUcUCKB9C3XjDYMRWsd1oPg/Be2EIb0wOn6Da8BrsbZkehtZ 05nlWW6AsV9/ydZ//qlEbSV75K6QE9eG/T9N50IjQ0wxCCfFeszvpyqI/mL48wY/+o5n lkGq0KDb5Oot/KlGx1cdmU13p6t3kUk0j0AbxfWYxmoRRUr2lQA+z4zAeSMphex8hvPe BgMTW71UX6oUbcgzkQTEyIhNtHT/O61ouw8EmGJERLS8cTtvC9yGDzOm7OV0rcji4B81 mccw== X-Gm-Message-State: AOJu0Ywd2R/0Enbznw/9Sy27nMOIZCKNyX+WWDrEfPlSbOdtjVVplE8G 4Dm1jdIYlSu6jpWPCatSZ5EOtPMFKwe9V6/4/d1kWnYs0yNR5V9YVJvwjnt8fn0XybdPWD25JcU G36vNBoUXM2sqHeRwX3R2diVcnvPrF7Z3NZL3vAgsfA== X-Gm-Gg: AeBDiesMrp2NlFM+A3eLDtHzYDyG4wLBKibGkw1OC59Tkz0RZXTg0j8SKPDVHnMVuJW nBa6vxkYJBUcpU/e4OKis2UFoMPLtfgpJRqy0dJKS+AB8Q+wp3EIX9xLrfDkjCrJU7sSkggzaxD I/xkT4yVOOKtwNkfnZYVB8Tfmy56+CRMAUWgLrWIEhUmRpAm3tUGX5nhwZDQcAUdNXlus4X5Elh yzpSW2uEsSrMxDoPw2aJllGkir/YdARPtcvyj0KD7o8ZRP3+OrEmOmu8zhqVCGR52AKAfhTnyYR PVIRbyprQc1K/YFmemy7rgJkh9LJ973MOzX7l2SvRzAXBX/oQ5j5dZwmBRN8LVXjXawXiHCiCa9 VvmnpB2BzgGyMgvajcq5fmzLJchb6yaxH43MYLFxBRYkuzYBgZiSeKX2nKaxYx2qfRtVoLNtvvw WXiSJBYA1rnEV9Nr3ich4dqg== X-Received: by 2002:a05:6102:1489:b0:607:9335:d09a with SMTP id ada2fe7eead31-60a00634adamr3006564137.20.1775896647867; Sat, 11 Apr 2026 01:37:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: jian he Date: Sat, 11 Apr 2026 16:36:51 +0800 X-Gm-Features: AQROBzDpokgZGfIzvn1r0qN57I1WBJFoeH59qRWr7fCPQy_Zt44a1lKmMIySJm4 Message-ID: Subject: Re: FOR PORTION OF does not recompute GENERATED STORED columns that depend on the range column To: SATYANARAYANA NARLAPURAM Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Apr 11, 2026 at 6:01=E2=80=AFAM SATYANARAYANA NARLAPURAM wrote: > > Following are still failing: > > (1) instead of triggers + views, mentioned in the thread [2], it has both= the test case and the fix. > I will check and reply in that thread. > > (2) For Portion Of DELETE loses rows when a BEFORE INSERT trigger returns= NULL > > DROP TABLE IF EXISTS subscriptions CASCADE; > CREATE TABLE subscriptions ( > sub_id int, > period int4range NOT NULL, > plan text > ); > > CREATE OR REPLACE FUNCTION reject_new_subscriptions() RETURNS trigger AS = $$ > BEGIN > -- Business rule: no new subscription rows allowed via INSERT. > RETURN NULL; > END; > $$ LANGUAGE plpgsql; > > CREATE TRIGGER no_new_subs > BEFORE INSERT ON subscriptions > FOR EACH ROW EXECUTE FUNCTION reject_new_subscriptions(); > > -- Pre-existing row (bypass trigger to seed it). > ALTER TABLE subscriptions DISABLE TRIGGER no_new_subs; > INSERT INTO subscriptions VALUES (1, '[1,100)', 'premium'); > ALTER TABLE subscriptions ENABLE TRIGGER no_new_subs; > > SELECT * FROM subscriptions; > -- 1 row: (1, [1,100), premium) > > -- Delete just the [40,60) slice. > DELETE FROM subscriptions FOR PORTION OF period FROM 40 TO 60; > > SELECT * FROM subscriptions ORDER BY period; > -- Should be two rows: [1,40) and [60,100) > -- Actually: 0 rows. The whole subscription vanished. > > SELECT count(*) AS remaining FROM subscriptions; > -- Expected 2, got 0. > I think this is expected. https://www.postgresql.org/docs/devel/sql-delete.html says <<>> When FOR PORTION OF is used, this can result in users who don't have INSERT privileges firing INSERT triggers. This should be considered when using SEC= URITY DEFINER trigger functions. <<>> We first tried inserting [1,40) and [60,100), but they were rejected and not inserted because the trigger function reject_new_subscriptions returned NULL. See ExecInsert: `````` if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->trig_insert_before_row) { /* Flush any pending inserts, so rows are visible to the triggers *= / if (estate->es_insert_pending_result_relations !=3D NIL) ExecPendingInserts(estate); if (!ExecBRInsertTriggers(estate, resultRelInfo, slot)) return NULL; /* "do nothing" */ } `````` > (3) FPO UPDATE loses leftovers the same way > > -- Shorten the meeting to only [40,60). > UPDATE room_bookings FOR PORTION OF slot FROM 40 TO 60 SET note =3D 'shor= tened'; > > SELECT * FROM room_bookings ORDER BY slot; > -- Should be three rows: > -- [1,40) team meeting > -- [40,60) shortened > -- [60,100) team meeting > -- Actually: only the [40,60) row survives. > For the same reason as above, I think the current behavior is correct. -- jian https://www.enterprisedb.com/