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 1wDkHC-003IoC-1k for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Apr 2026 14:34:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDkHB-00AIFK-2x for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Apr 2026 14:34:33 +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 1wD5QY-001brR-2g for pgsql-bugs@lists.postgresql.org; Wed, 15 Apr 2026 18:57:30 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wD5QW-00000001C3V-2oXn for pgsql-bugs@postgresql.org; Wed, 15 Apr 2026 18:57:29 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-386b553c70eso7428291fa.0 for ; Wed, 15 Apr 2026 11:57:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776279447; cv=none; d=google.com; s=arc-20240605; b=ijURKd/pNc0O1WJJBgG6D4PdUb3l3WD4ZRBfBNijuLVzItobt4e/NFHgW8w4rCDU5+ +07/HJJNNJxpbYkAUJgsnH7Ao69dH3NzhVkEqTzteJ4MQ2aB94hqNYXh7Pu3+tx4maJo AO3Y3qJCZyqdmzGrtFBmxph8BEFSY9tjkrwzuy2n+BH2kYIbZ871r16vrUYSyRm7ij23 QRhETARUb8KsAMJZFf4+GEYov+Ik4c4Rl3fZo0KhXRoJios63WBGnhVJiqCq6Ui+KQ0Z 6wleqVqZeq7XUR9KvM3JClV8vIX8hydwXl0wQDjS3jZsZJnkkL6wIpX9eWOFetF6OFqy xE8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=VQ6UgLT+VLxKXCdbjqmP0ViOE7PQAimandh7lyKsD2U=; fh=ew3FAQN7/zRx8MOKidAKWMlEqGOMNEq8X1fzXXEB9h4=; b=lMIoro8Y0/WXOWM8T6sT0HcY1IHgebIPmYsafwxh7lqKRyyyekQHXfxMZ8gtnwTKXK CIxmPAA118YGS8Yk3YBc10Xjq3tI6qLHFx5eKvkuaZ7E01YHcObEgeJ0sf4LAUeA6G6/ biDcDg7N/mZ7iu+7Z1TzDOcKBF4qmLn6YOAxKJyGA0LnEtNhTtsFk0QtdfOxgS07denW mpID9hS6g5Mi8/KI+kh8qFKhYANlDgFvSHwIGb9VkxYUoSF12ORTe/MB/s5XHcQ8yswk 3CTo7fvdL/CvGu7yX99zsicAv6lZQQBwfIamXlUcd5o/aeUrZnxAojJ8DsBL79ydopLV b+GQ==; darn=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=1776279447; x=1776884247; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=VQ6UgLT+VLxKXCdbjqmP0ViOE7PQAimandh7lyKsD2U=; b=lYdAzUZFJ8f899U5U+GsCzLls1V2HdRudECdAU0Czxdc+mmCVFi0KPpB+V+cbGCEVr pSXWf1/qQCdIyUZj62EHH2hLIsdppY0rfa13bhj0NOmndC9Y+7Wr+asFajsEEChtkPgC ACuRMO/xr3MnzI/q43Oz3EESuNlLF2Cazx6ji78eLRHXcRy7DFnhpM1hfWxpnddL0Eaj JufapalmjHygRSEr673AF8K3WCHjON5DZWQFOYqcrTat5Ts2PdMju8rYPwnP6eZKbnVg +iX1o6aYOwZ8fo5bW3IFrBuu+x6UAmzZhX5F0nDwVLIf7fZYzkSAdmF+07miA0g8BrAu bJ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776279447; x=1776884247; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VQ6UgLT+VLxKXCdbjqmP0ViOE7PQAimandh7lyKsD2U=; b=KHDcQ45dcIRpZKDb7itm4fyMr+pk4k8Ix8HnwmCILIofDDMKmX4CL02uXvW0sqzjyJ PA8iqYUJYWT2wWQRnQgcWHL3ILBbuGAmx2GiY/tp4dI45o2iLIsPAGeoQ6eKsi8s2KVH q3MKrqU4zHsQVrTjDrLtbFm6bZ6tw1nVVZLMpTijZKXJzFIQXdM4aAaW7rlJvz7XAVqW vt5fNluVTK6tjQvV7n4GSNz05FlP7wiZB3+BWh4eAB+gXj5sHtOThVricu0MhsCS2al8 GEKIVc6GH4BXYDo5Hjo3EPd+8ELSzD/KH8mh5zWRdBH/DWT04AAdwqzXwoNfilJIfX9e rowA== X-Gm-Message-State: AOJu0Yxj9DlHz9z8UebSQDlxxVe+DguEMTm3Hpk8KJQ8FxC9sl9oZOcI Zhik/UzzufXiadaG15iU0YcUZ2nSRNy2H+OWXOMEbwohy+U/unZfapGASEx86ouFthYR5dpVXym bp0ojTGbfo+BkLynI4fol11nHJcSIuQuurSW7giM= X-Gm-Gg: AeBDiev6dWHSyCRWlhnxs+c9wzR/qr6ayNQinF+QHo3aT+amLbPGCkAM/xyxVw6e+mh W/8P/wVU9p+cvyAqJnGWWhBjplAwrupxfb4ZsOZk/pvgiRYVj3D23D+txyBnZaimJN/Okk6ei9M Rt6qOyLg5MobYBPOQBALk9Y/JhxZTZ7/4BQSCjHHFHnhQPrIlemRhG0vFdrK+4+bIgTU1kGNqZ2 Q10h5mTUIxEXeiyz6a8axXAl++zMn9BWadE5SQO6hRcpdPXkJM5UuK+8oJDO974YwF2Z7IbJlGy 1abb8YOwKf87+pLD+PpZ6pKdLL0dlVRb2rR9WsEhGnNNIxZfbXZ42vu9K1EbUg== X-Received: by 2002:a2e:a553:0:b0:38e:4dd:5c2a with SMTP id 38308e7fff4ca-38e4bf03892mr68099771fa.17.1776279447213; Wed, 15 Apr 2026 11:57:27 -0700 (PDT) MIME-Version: 1.0 From: Leendert Gravendeel Date: Wed, 15 Apr 2026 20:56:50 +0200 X-Gm-Features: AQROBzAsDnrquYrrhdyB54FUa8_yFh4ORwXgeQsTGUyPL7gIlhTbRcPP4tPyBdk Message-ID: Subject: BUG: PL/pgSQL FOREACH misparses variable named "slice" with SLICE clause To: pgsql-bugs@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, I believe I have found a parser issue in PL/pgSQL involving the FOREACH ... SLICE syntax. Version: PostgreSQL 18 (reproduced on current release) Description: When using FOREACH with the SLICE clause, a loop variable named `slice` is misinterpreted as the SLICE keyword, causing the statement to fail. Renaming the variable to anything else makes the function work as expected. Reproduction: CREATE FUNCTION test_slice_conflict() RETURNS text LANGUAGE plpgsql AS $$ DECLARE slice integer[]; arr integer[] := ARRAY[[1,2],[3,4]]; BEGIN FOREACH slice SLICE 1 IN ARRAY arr LOOP END LOOP; RETURN 'ok'; END; $$; Observed behavior: The function fails to compile due to incorrect parsing of `slice` as the SLICE keyword. Expected behavior: `slice` should be treated as a normal identifier (loop variable), and the function should compile and run successfully. Additional notes: - Renaming the variable (e.g. to `abc`) makes the function work. - This suggests a keyword/identifier ambiguity where the parser prefers the SLICE keyword in this context. Given that the documentation describes the FOREACH target as a regular variable, this behavior seems unintended. Please let me know if additional information is needed. Best regards, Leendert Gravendeel