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 1tBGKn-002mRo-5v for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Nov 2024 16:35:12 +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 1tBGKk-00FZgb-5G for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Nov 2024 16:35:10 +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 <9erthalion6@gmail.com>) id 1tBGKj-00FZgT-RM for pgsql-hackers@lists.postgresql.org; Wed, 13 Nov 2024 16:35:10 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from <9erthalion6@gmail.com>) id 1tBGKd-001gy7-Px for pgsql-hackers@lists.postgresql.org; Wed, 13 Nov 2024 16:35:09 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-539fb49c64aso10408287e87.0 for ; Wed, 13 Nov 2024 08:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731515702; x=1732120502; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=26NnNTx1diezrXTXRpOEnVU8q8ka1zptcBQY2WZwGWs=; b=at+s+LFNBJCeaCqPy6Cgf2szgAAUw7Ccb6NoCVgfIvaUj26UWXbCbw8cLaXIwlAzuH A/DH/2udXX4KLcnlZ2hgMmG9SMRooavePJT/fEmHXuJ0TnA7T2BUZIfaRBNggRles5m1 CNXsCrpHX7L60aW/Kh9mK9/6fXLBZP1J7MSgsjW7zcI/dqdc8ebm+D5QZQGtRH4rNFBl U2Dq1PAuWoQ1ibIzxdP3F2YJmNteiQzp6O+OccYXu7MgIa8YJUD81dCfExrad+NdmKDg qqIMyftC+87fXAx60TGRoa+sfI9HJwoO1bhNjm5w4lGKJXfZR3/CurB8Lk9MS0gA74PJ Dulg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731515702; x=1732120502; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=26NnNTx1diezrXTXRpOEnVU8q8ka1zptcBQY2WZwGWs=; b=ayIJ9aOSzVDagJPuMD+5epHmR22x5QK18+96uuBwOPFgLQv1SBirNpmcoE/kh8ddFb Bt43QQx2Ryil/eMDV89oJq5QZd+BiGVpvS7MctnAVZK1+86SJXZ5+Lnk3IRdvvbTiz2H xygR34PnzvZGUzhmEGemWdVEWq09BR8g7FZBmi3CKCBrHyeBVKLv5CqRXKaZVRl+di3k bFLOSU9EdwqYEvIowJ4UPAdNL3HGzUK9efO2t1BZSd4rgIm4G4fsEF188/dbuAkQi76b /njhV3BnceGrTvgq80C6zmFZRgHTKxawupaxXy5bNlkw5PPPbExmWDLlWIUwqyYM6DiH U7rQ== X-Forwarded-Encrypted: i=1; AJvYcCVrZjHM1+0zmdFHV6CU+rx7axnF+FaspHDYRIpX4kvcOar6XGilqlyJ75jJstoolhdou+VE0WqxNqOTThiR@lists.postgresql.org X-Gm-Message-State: AOJu0YxmUYdeHi6vVgvCji1uZ74ggeHbM0jZWoJPvME3UWgtwmJatx6A qTZnsEaPR3JFJTQoVzwbO0cLkC7+XkmLKgq7rhowZ2e3O76w77xL X-Google-Smtp-Source: AGHT+IEb/OgYhnNi1wEho5r0AzIyJeD+FDFxEqU3HIbgg44545LT5qvsGgaGgCZmJd9GyrJnStpIOw== X-Received: by 2002:ac2:51a3:0:b0:53d:9ff9:d4f with SMTP id 2adb3069b0e04-53d9ff9110fmr2474049e87.24.1731515701708; Wed, 13 Nov 2024 08:35:01 -0800 (PST) Received: from ddolgov-thinkpadt14sgen1.rmtde.csb ([57.133.64.210]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0dc570asm883787166b.111.2024.11.13.08.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 08:35:01 -0800 (PST) Date: Wed, 13 Nov 2024 17:34:59 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Pavel Stehule Cc: Laurenz Albe , Erik Rijkers , Michael Paquier , Amit Kapila , DUVAL REMI , PostgreSQL Hackers Subject: Re: proposal: schema variables Message-ID: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> References: 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 > On Sun, Nov 10, 2024 at 06:51:40PM GMT, Pavel Stehule wrote: > ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule > napsal: > I thought a lot of time about better solutions for identifier collisions > and I really don't think so there is some consistent user friendly syntax. > Personally I think there is an easy already implemented solution - > convention - just use a dedicated schema for variables and this schema > should not be in the search path. Or use secondary convention - like using > prefix "__" for session variables. Common convention is using "_" for > PLpgSQL variables. I searched how this issue is solved in other databases, > or in standard, and I found nothing special. The Oracle and SQL/PSM has a > concept of visibility - the variables are not visible outside packages or > modules, but Postgres has nothing similar. It can be emulated by a > dedicated schema without inserting a search path, but it is less strong. > > I think we can introduce an alternative syntax, that will not be user > friendly or readable friendly, but it can be without collisions - or can > decrease possible risks. > > It is nothing new - SQL does it with old, "new" syntax of inner joins, or > in Postgres we can > > where salary < 40000 > > or > > where pg_catalog.int4lt(salary, 40000); > > > or some like we use for operators OPERATOR(*schema*.*operatorname*) > > So introducing VARIABLE(schema.variablename) syntax as an alternative > syntax for accessing variables I really like. I strongly prefer to use this > as only alternative (secondary) syntax, because I don't think it is > friendly syntax or writing friendly, but it is safe, and I can imagine > tools that can replace generic syntax to this special, or that detects > generic syntax and shows some warning. Then users can choose what they > prefer. Two syntaxes - generic and special can be good enough for all - and > this can be perfectly consistent with current Postgres. As far as I recall, last time this topic was discussed in hackers, two options were proposed: the one with VARIABLE(name), what you mention here; and another one with adding variables to the FROM clause. The VARIABLE(...) syntax didn't get much negative feedback, so I guess why not -- if you find it fitting, it would be interesting to see the implementation. I'm afraid it should not be just an alternative syntax, but the only one allowed, because otherwise I don't see how scenarious like "drop a column with the same name" could be avoided. As in the previous thread: -- we've got a variable b at the same time SELECT a, b FROM table1; Then dropping the column b, but everything still works beause the variable b got silently picked up. But if it would be required to say VARIABLE(b), then all fine. And to make sure we're on the same page, could you post couple of examples from curretly existing tests in the patch, how are they going to look like with this proposal? About adding variables to the FROM clause. Looks like this option was quite popular, and you've mentioned some technical challenges implementing that. If you'd like to go with another approach, it would be great to elaborate on that -- maybe even with a PoC, to make a convincing point here.