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 1vdBoO-00F5Yx-11 for pgsql-general@arkaria.postgresql.org; Tue, 06 Jan 2026 18:29:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdBnM-009pHh-1P for pgsql-general@arkaria.postgresql.org; Tue, 06 Jan 2026 18:28:41 +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.96) (envelope-from ) id 1vdBnM-009pHY-0E for pgsql-general@lists.postgresql.org; Tue, 06 Jan 2026 18:28:40 +0000 Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdBnL-004ZjG-1Z for pgsql-general@postgresql.org; Tue, 06 Jan 2026 18:28:39 +0000 Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-88888d80590so13776656d6.3 for ; Tue, 06 Jan 2026 10:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767724118; x=1768328918; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=09Nq/+eMeVdL5MmgoW8ISw0bJUHT1HqG/Qmj5OyQHX0=; b=K1xRKhAj2Hi0BUAaUrc1HzNwFghCI80rjwU4f1cJZrM8k2wOyHG4U1SHZkCAhINvPD KkjMUrQQhSvdYfqQUBjIYZnHvbtmUCmUt01pyLbFiyAY4ZPpxHs0ONWzUbVW1HT2l280 bUG9VXNP7h1I6URkFvyfnNJD2DOwQGvjIiJuZnL7jKhlVCaPOGfTBVAvkkXlGL2ngWSZ /0g86F4frkQMk0x32MgIAgjWp4tviMGLKndpT4LB1w3r9cWOaA3ykcOrOAsNi9diUUDl nQdw8545lt288cmKDRewLjBfc0eAQdFVTNEJY9Br0bDgdePGIoxcs+W7088EBC9ji4OL cTcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767724118; x=1768328918; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=09Nq/+eMeVdL5MmgoW8ISw0bJUHT1HqG/Qmj5OyQHX0=; b=E10cbbq6U57vzkpsjlaRsbBbUB14ch/07M2lrM1j7oqa9obg1PIJK1Sv+Sv5nnlR/7 zhob9gWot3drsSuUisg+qGxH3agqpcqpi7zMksfdFuJ14h1q1WbT4Hv7ql23DDiu6hTL tLjWSu8RERKd00h/VqTXNR8HBIywR1fVyaZAewph/lYauJGpzdlJ9ggWHmyo7tq5ySNr pD7sM9eAJatOslnerLooXAaY3S72hyoZZvMaoOlpFALDnzoAWHyRJ4gwIsHlLWB3Vxwc eZiDORAWro9IQwlLv5ARfbwalknDlSfEidiJo+JfmcuNaYMEVeIzzad8dassMSQD0K8d djQg== X-Gm-Message-State: AOJu0Yz/gt6xgh5DMLR75cR3jMT4+xVfr8ZoxfAUsl2smz5pTicBX3ls zl5ndjRZrzvizdRn1HWrNIPMZk2YOjXwwEgZyffRCZ75CF6ZNdn6L/W8Ktyy5Q== X-Gm-Gg: AY/fxX5Am7E38LhfcTVPL7RXL7M0cVTDkUGM+1j7B0c6C8j2KQk/gaSw8bDgdqV5xxZ Jf8PMadcEzcU3yWe9mD81V6T6wV5j5g841SFzGiCDfPX3IhzE8JhfVQFcFq1QAjyf1zA5NOBEDJ qXPbZizURqfCIirfdZHS6iNUiPZdT7WgBtMGVJzO4hCmi5QxACZ6WETHg1i5Ifip3i/jFBql057 b5mAeyejzbS6Q7dKemleGzDEuzjThoasuY2octvQ/s+1Eq5F1iPskfIoxaSHyyEC0qnNU544DaS yXkc8l37qM2qo0VmjAO8dMeEZ3X9WkP1CiqxLzIpOotgb91sEoI1tMTDGcj6XgD1bOKWS4Myg9o 7OFC+YU8DlQGevQwGFifuzOkmVw45Q5qIAPh64oVWoJ/Wi4E11avlsV46dpZBz8pYT1ttFpGrhb AP5pfxMybXoRJ/acAXs4LMhT8+DbqNZjyDd+yeg1LDk8/IGWo8sQmzJQuQ6NMqtCjJ X-Google-Smtp-Source: AGHT+IGJptjlXMjgLS2gkEUBiZmM7ar0g6k9+n+XOOuQZtDhIE44g+O4Ks3W+/S2WzYifaAe2z/fjQ== X-Received: by 2002:a05:6214:2b88:b0:890:2509:1057 with SMTP id 6a1803df08f44-89075ecf1d1mr49619686d6.47.1767724118211; Tue, 06 Jan 2026 10:28:38 -0800 (PST) Received: from smtpclient.apple (dhcp-67-145-242-116.gobrightspeed.net. [67.145.242.116]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8907724ef14sm18018736d6.38.2026.01.06.10.28.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jan 2026 10:28:37 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: pg18 bug? SELECT query doesn't work From: Eric Ridge In-Reply-To: <9A42D802-5994-4DAF-86FB-AB5954840216@gmail.com> Date: Tue, 6 Jan 2026 13:28:27 -0500 Cc: pgsql-general Content-Transfer-Encoding: quoted-printable Message-Id: <07A953A0-D33C-481B-A411-93D7F89C290A@gmail.com> References: <7900964C-F99E-481E-BEE5-4338774CEB9F@gmail.com> <11E075EF-20F5-42CD-A014-16172FF05CCF@gmail.com> <9A42D802-5994-4DAF-86FB-AB5954840216@gmail.com> To: "David G. Johnston" X-Mailer: Apple Mail (2.3826.500.181.1.5) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jan 6, 2026, at 1:10=E2=80=AFPM, Eric Ridge = wrote: >=20 >> On Jan 6, 2026, at 12:00=E2=80=AFPM, David G. Johnston = wrote: >=20 >=20 >=20 >> That the behavior depends on the chosen plan and plans differ when = you do and do not materialize a CTE is likewise not surprising.=20 >=20 >=20 > I guess I wouldn't expect Postgres to generate a plan that it then = can't execute. That's what's surprising to me. Sorry, one more thing. The reduced case fails on v18: # explain SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog'])) as = animal FROM generate_series(1, 10) GROUP BY 1) x WHERE animal ILIKE = 'c%'; ERROR: set-valued function called in context that cannot accept a set LINE 1: explain SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog... ^ But if you remove the outer WHERE clause it works: # SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog'])) as animal = FROM generate_series(1, 10) GROUP BY 1) x; animal =20 -------- CAT DOG (2 rows) I can't get an EXPLAIN for the former, but for the latter: QUERY PLAN = =20 = --------------------------------------------------------------------------= ------------- HashAggregate (cost=3D0.63..0.64 rows=3D1 width=3D32) Group Key: upper((unnest('{cat,dog}'::text[]))) -> Result (cost=3D0.00..0.58 rows=3D20 width=3D32) -> ProjectSet (cost=3D0.00..0.28 rows=3D20 width=3D32) -> Function Scan on generate_series (cost=3D0.00..0.10 = rows=3D10 width=3D0) (5 rows) That's all. I promise! eric=