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 1u150v-00Dhvy-9G for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Apr 2025 15:00:53 +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 1u150t-00EGrS-5x for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Apr 2025 15:00:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u150s-00EGrJ-NO for pgsql-bugs@lists.postgresql.org; Sat, 05 Apr 2025 15:00:50 +0000 Received: from fout-a4-smtp.messagingengine.com ([103.168.172.147]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u150q-0037ei-1D for pgsql-bugs@lists.postgresql.org; Sat, 05 Apr 2025 15:00:49 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 4C0EA13801A0; Sat, 5 Apr 2025 11:00:47 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Sat, 05 Apr 2025 11:00:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743865247; x=1743951647; bh=5 T5I0aD90HxBen+AriEF8br9nV+C/yIYL4RDkKYf8dc=; b=sE/jXdKsvMHdNH1vQ 6sezd2u2/o4hQSiKsJsfVg7ggPZLQ3SSZRWMbAgKfmk0j3tVDI37VIvoyANEtInW a2p0hqYR8y8KZd+VvjBWbpZX7C14rlFqHFU81kG0mBLciSTshXSuazfaNIOHtZ9N ZYRs9bbj/XPjeVpwrbNKmSbQAWxdR1VBQ75q/9VaCEpCWUBGivo0h317e7gnL67i s+TjD67Y8soZF+VbWcZqgSSfL07C05ema51VR7WgaJHiAC3kC6IuMGWcXS0mU86B ysSVHRXbuuLWAsq++RAVMNhmQSOkK4/FPB8AL8ILXbR9xzK9WofM9GPhBsg67H8y SzBNA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleegieehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhf fvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghrohcujfgvrhhr vghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqeenucggtffrrg htthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeejkeffgfdufffhudff ffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegr lhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtph houhhtpdhrtghpthhtohepphhgshhqlhdqsghughhssehlihhsthhsrdhpohhsthhgrhgv shhqlhdrohhrghdprhgtphhtthhopehluhihjedtsehpshhurdgvughupdhrtghpthhtoh epthhglhesshhsshdrphhghhdrphgrrdhush X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 5 Apr 2025 11:00:46 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1743865244; bh=vCKfRHLxjN89HaI+P5c5hhTpy5HJ3fsWpbJmrjgAsqo=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=P30ZSh3zyMrl46pypJcMe5SwrPDjJYSDFveUt8GolEFCe1A/ddowP+9OuxCw9hh7K HF7jNpv+w3ozPCVN7SpE/c7BH59ZblnITegfLTyfPXej/RcwA2dINN/kfFvUfZhWYL sR+QNV9LtJV+p8l+XB4b2lAVR5n/TUlPh6S1pXR35nDqoQuJwjf+xvd8NBAkXaZNIz MObYRgm8d8DUFjNflb5aewKb63kj0RorUBoEDTavSoLEmzAnhwQtOiElmwRrqy0o45 baRTAS/iIk3T7Jdb68KuzDVmToucVWddXZykVx6zohIaTDPwHCnlydQrs+PaYkVptX uC63olEoJPbQQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 4690F8F; Sat, 5 Apr 2025 17:00:44 +0200 (CEST) Date: Sat, 5 Apr 2025 17:00:44 +0200 From: Alvaro Herrera To: Tom Lane Cc: luy70@psu.edu, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18877: PostgreSQL triggers assertion failure Message-ID: <202504051500.v6ekizm5fcv4@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2459196.1743864448@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-Apr-05, Tom Lane wrote: > Yeah, I spent some time looking at this and came to similar > conclusions: it's not easy to produce the same error without > a significant investment of work. (For example, determining > the targetlist length pre-transformation seems impractical > because it could be "SELECT * FROM ...") Right. > However, after looking around there is more not to like about this > code, as demonstrated by this example from the regression tests: > > regression=# CREATE VIEW json_array_subquery_view AS > regression-# SELECT JSON_ARRAY(SELECT i FROM (VALUES (1), (2), (NULL), (4)) foo(i) RETURNING jsonb); > CREATE VIEW > regression=# \sv json_array_subquery_view > CREATE OR REPLACE VIEW public.json_array_subquery_view AS > SELECT ( SELECT JSON_ARRAYAGG(q.* RETURNING jsonb) AS "json_arrayagg" > FROM ( SELECT foo.i > FROM ( VALUES (1), (2), (NULL::integer), (4)) foo(i)) q(a)) AS "json_array" > > That is, we are exposing the implementation of json_array() in > a way that makes it impossible to change. If we ever discover > that json_array() isn't exactly equivalent to this json_arrayagg() > invocation, we'll be in deep trouble. We've expended a lot of > sweat in the past to avoid exposing implementations this way, > eg 40c24bfef, fb32748e3. Oh, of course. I failed to realize this at the time. > So what we should be doing is building a parse-analysis result > that deparses into something that looks like the input; probably, > a JsonArrayQueryConstructor node with an analyzed EXPR_SUBLINK > SubLink below it. Then we can make this tlist-length check against > the analyzed SubLink, removing the problem of premature errors that > are not spelled the way we want. Sounds reasonable, I can try to find better coding for this, but it won't be soon. I won't be sad if somebody else wants to do it, so if you feel like it, please be my guest. > Anyway, that idea is far too invasive to be back-patchable, > and IMO it's too late to consider even getting it into v18. > So what I'm thinking is we should just apply the copyObject > hack for now, and resolve to reconsider this code later. Sounds reasonable. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Crear es tan difícil como ser libre" (Elsa Triolet)