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 1qg7GV-00EVBV-GX for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Sep 2023 17:33:31 +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 1qg7GS-009sBC-Ir for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Sep 2023 17:33:28 +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 1qg6k8-009o0U-4J for pgsql-bugs@lists.postgresql.org; Tue, 12 Sep 2023 17:00:03 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qg6k0-004BOy-Sy for pgsql-bugs@lists.postgresql.org; Tue, 12 Sep 2023 17:00:02 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-52e297c7c39so7406831a12.2 for ; Tue, 12 Sep 2023 09:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694537994; x=1695142794; darn=lists.postgresql.org; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=Kh8zQX5vcUriKeB2+L5D+Xb66SIKlpXTP+vNmuFhbVQ=; b=Aii9pZzlXaXzjr1TFqXCpS+jdJ2w1Ob//N4cmF+RSGZdTIRCDritJpsJ0PXPozHCmv yCEdQh5bpE+F6PM0IKZ+szQEN2SbUB+QTjjYRYS673nkgQkn0wapJSpQppyCZ8GYOzao 7sO2F26e992VmVTKbYhvXcNSYYXfEkUo+ZKNrbnR10xGT30aRn85pl+K4GbuOZEofBDn 7+Z/WTVnv7dhdEYtsgCai5CiYnkHkrPsM0DeoADjMvqPzk2UcgV2UnmDy6LJ3eiaPiQc +ft7ogkTNRVzEuadbHDbe/Lg4rU8aV1GHzTiI+HfVQT+PNt36prQMtZ8SVEJTjXhnlYc SwxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694537994; x=1695142794; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kh8zQX5vcUriKeB2+L5D+Xb66SIKlpXTP+vNmuFhbVQ=; b=d5p4zsrWlGTsStbxjvZgB2xYoCi0dBD9cJYEC2rEz9shFu+Jg5DM0OrU60YNXOIvxY kCdy3QbsNEpJpozWphaM1ZqC6tjSMQ9VFcnvfDtAfvEYsBNC8j4xLEraGyriS6kPjdqo xaplhRJ9mmbA9GeDE4lRSC295gHBcVs5jemVSh6dAitSmBsGeQQAP/kQLofsIaRpaiNd xqiAawlykFEwlQnhV62BHMfT4jRPl5jPaHxeTJYE8896pM9AGd1GJ+O6aNA/GRQFOIXP ybZsKNZ4buwN/Bv4bm+Qhj9gdsWULoOOm1kjEsf/3HjrUumm1C20jhEo52adOltySm2f rMdQ== X-Gm-Message-State: AOJu0YwhwvP6MEmPfgr2AOg1nLpxzWkYKco0DvUfqKAQ0WVQbROC+glh oB6Bl4oJUvv+ZzYw64zaM4BDzwQD4lg= X-Google-Smtp-Source: AGHT+IFGmDvjVQ87RBi+Umtht77+Pcpr7b6TAskvpqWiH005TgmhAlmedjci3h4nJlbgAr+up3dWCQ== X-Received: by 2002:aa7:cd46:0:b0:52c:9ce1:f117 with SMTP id v6-20020aa7cd46000000b0052c9ce1f117mr148966edw.40.1694537994161; Tue, 12 Sep 2023 09:59:54 -0700 (PDT) Received: from smtpclient.apple ([2a02:58:14a:c400:e853:b905:5d6d:bc95]) by smtp.gmail.com with ESMTPSA id s6-20020aa7c546000000b00521953ce6e0sm6124114edr.93.2023.09.12.09.59.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2023 09:59:53 -0700 (PDT) From: Aleksandr Vinokurov Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Subject: "as name" is shadowed by name "value" when selecting with "left join jsonb_array_elements(d.items) as item on true" Message-Id: <7AC1DE23-F815-421B-8F01-C49A8764354D@gmail.com> Date: Tue, 12 Sep 2023 18:59:43 +0200 To: pgsql-bugs@lists.postgresql.org X-Mailer: Apple Mail (2.3731.400.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello good people, I=E2=80=99ve stepped into a bug today, where the requested name is = strangely shadowed. Consider three following examples (in short =E2=80=94 check the = =E2=80=9Cvalue=E2=80=9D column name in the first result): ----------------- select *, item as item from (select '[1]'::jsonb as items) as d left join jsonb_array_elements(d.items) as item on true; items | value | item -------+-------+------ [1] | 1 | 1 select *, item as item from (select *, jsonb_array_elements(d.items) as item from (select '[1]'::jsonb as items) as d) as f; items | item | item -------+------+------ [1] | 1 | 1 select *, item as item from (select '{1}'::text[] as items) as d left join unnest(d.items) as item on true; items | item | item -------+------+------ {1} | 1 | 1 ----------------- All three request name to be =E2=80=9Cas item=E2=80=9D, and for last two = everything is as expected. But the first one is strange: 1. It shows the name =E2=80=9Cvalue=E2=80=9D for the column for which = the elements were requested to be named =E2=80=9Cas item=E2=80=9D, 2. but on also it does not fail on making a copy of the column = (referenced by name =E2=80=9Citem=E2=80=9D as =E2=80=9Citem=E2=80=9D). Actually you don=E2=80=99t need to make it =E2=80=9Citem as item=E2=80=9D,= it can be =E2=80=9Cbuggy_name as item=E2=80=9D if you make it "left = join jsonb_array_elements(d.items) as buggy_name on true=E2=80=9D =E2=80=94= the way =E2=80=9Citem as item=E2=80=9D is just a workaround for now to = have a column with the desired name and data. That behaviour was observed first on PostgreSQL 12.16 (Debian 12.16-1.pgdg120+1) on = aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, = 64-bit and then=20 PostgreSQL 15.4 (Debian 15.4-1.pgdg120+1) on aarch64-unknown-linux-gnu, = compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit If I can help with something else, please let me know With best regards, Aleksandr Vinokurov=