Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAJ3Z-0002D5-Gu for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jan 2022 22:03:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAJ3Y-00029u-AY for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jan 2022 22:03:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAJ3X-00029k-Vr for pgsql-hackers@lists.postgresql.org; Wed, 19 Jan 2022 22:03:52 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nAJ3V-0005Xz-TH for pgsql-hackers@lists.postgresql.org; Wed, 19 Jan 2022 22:03:51 +0000 Received: by mail-pj1-x1033.google.com with SMTP id o3so3811357pjs.1 for ; Wed, 19 Jan 2022 14:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=8xKdqcaKKpyKR08Xv+X5pfIeBUO8BkjkVC5lu3EMQG4=; b=J/NpZh0e0IbsAIcO5yJg/VZ6GGhX8HhNqupCtYtgr0W+BWT4tcHIshiRcRb/nnd6eB dJqOeRXuoXPnJ5RdGm7fBTBDnLK0MVN9fjo8TpIr8Aayda2pFBesMRWKMqPSW7+9WpW2 hYp64fYvyNh+6up95/+FuxIg5059/AeWDSlKb7OrGVDPERorkQ9iHmB4f8M9r7PxnsZX fRSdaJm1zkoaJYnnUHEC78a55GJo70t9UBqiOZJ5db6mT/23v6kcpHJU1z2eJCUGjqEz hkrpH1WZAmpaLKbzfLBx7FWQM+9bmd0Ccu5/Paou63Wco3odafjOMh0jYBIj7GOb8gpz kxiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=8xKdqcaKKpyKR08Xv+X5pfIeBUO8BkjkVC5lu3EMQG4=; b=0/COAJIYY26NI03rST7f1OUzLwQoIUw6gVGE/tdyip+UGTm+9rOO3YAJTRo5GGqwHt HxtnnzOwNs95V6deK/IcGaxfcA7p1vEwRIDGbR60g4EvBGxy8OvzxlkqpiAJHVrolPXA GmSHHUt9UkXdAaEQsHoJ5TS61zz1IcW4BKpOupp/mNDnANv+Sj3dE8zshH7DQHZi93EN C9Bkjqjm6gZDNBqyofvxD7C0lYXl/ORo/Uiw1afOllDaN3ntWmG3Ps50jCMfdjjVE1D/ 282waVDRvSytmG9GfLVjiltKu4zls5jIHMfY0QUV7mGhrHyX5xdP72zK8jWJZvThj8aF uOmw== X-Gm-Message-State: AOAM533meHO4H6bLinih6Vk+ql+dUrTHbIsKo3qqB3hUE/PRVv2N9wu7 QEHcAFq0lixMX0RnnGlSBRw= X-Google-Smtp-Source: ABdhPJx9CaJyitsg//4Sdmh/0KlVpuc7tOGNV5zuRLjRvKA4rrgBYXetnZPsF/6553jgqnQFRLOgYw== X-Received: by 2002:a17:90a:c694:: with SMTP id n20mr6854651pjt.66.1642629827318; Wed, 19 Jan 2022 14:03:47 -0800 (PST) Received: from jrouhaud (1-171-55-158.dynamic-ip.hinet.net. [1.171.55.158]) by smtp.gmail.com with ESMTPSA id o18sm604447pfu.45.2022.01.19.14.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 14:03:46 -0800 (PST) Date: Thu, 20 Jan 2022 06:03:40 +0800 From: Julien Rouhaud To: Pavel Stehule Cc: Dean Rasheed , Joel Jacobson , PostgreSQL Hackers Subject: Re: Schema variables - new implementation for Postgres 15 Message-ID: <20220119220340.m5xtlwuinywcncvd@jrouhaud> References: <1ebeaf57-da83-42e1-9302-fb126281814d@www.fastmail.com> <20220114024402.btyn7vrpkhnso2bq@jrouhaud> <20220119080117.4c2fjzs5p7vtdxhk@jrouhaud> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Jan 19, 2022 at 09:09:41PM +0100, Pavel Stehule wrote: > st 19. 1. 2022 v 9:01 odesílatel Julien Rouhaud napsal: > > RAISE NOTICE should use local variables, and in this case is a question if we > should raise a warning. There are two possible analogies - we can see session > variables like global variables, and then the warning should not be raised, > or we can see relation between session variables and plpgsql variables > similar like session variables and some with higher priority, and then > warning should be raised. If we want to ensure that the new session variable > doesn't break code, then session variables should have lower priority than > plpgsql variables too. And because the plpgsql protection against collision > cannot be used, then I prefer raising the warning. Ah that's indeed a good point. I agree, they're from a different part of the system so they should be treated as different things, and thus raising a warning. It's consistent with the chosen conservative approach anyway. > PLpgSQL assignment should not be in collision with session variables ever Agreed. > > > > > =# DO $$ > > BEGIN > > v := 'test'; > > RAISE NOTICE 'v: %', v; > > END; > > $$ LANGUAGE plpgsql; > > ERROR: 42601: "v" is not a known variable > > LINE 3: v := 'test'; > > > > But the RAISE NOTICE does see the session variable (which should be the > > correct > > behavior I think), so the warning should have been raised for this > > instruction > > (and in that case the message is incorrect, as it's not shadowing a > > column). > > > > In this case I can detect node type, and I can identify external param > node, but I cannot to detect if this code was executed from PLpgSQL or from > some other > > So I can to modify warning text to some Yes, that's what I had in mind too. > DETAIL: The identifier can be column reference or query parameter or > session variable reference. > HINT: The column reference and query parameter is preferred against > session variable reference. > > I cannot to use term "plpgsql variable" becase I cannot to ensure validity > of this message > > Maybe is better to don't talk about source of this issue, and just talk > about result - so the warning text should be just > > MESSAGE: "session variable \"xxxx\" is shadowed > DETAIL: "session variables can be shadowed by columns, routine's variables > and routine's arguments with same name" > > Is it better? I clearly prefer the 2nd version.