Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e7cUa-0007Lq-EK for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Oct 2017 07:22:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e7cUZ-00035O-AO for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Oct 2017 07:22:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e7cUW-000345-So for pgsql-hackers@postgresql.org; Thu, 26 Oct 2017 07:22:12 +0000 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e7cUP-00016A-BG for pgsql-hackers@postgresql.org; Thu, 26 Oct 2017 07:22:12 +0000 Received: by mail-wr0-x235.google.com with SMTP id z55so2211582wrz.1 for ; Thu, 26 Oct 2017 00:22:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=C9sOrNkBbxcA0c7i40XbVYeVVNlHQPWI3s5+j+nAL0Y=; b=ehvskPzFUwOBbxiRQlRc71HYuZLOavqB4dSFMPwUeYqAjifTyQ5DaGaA+mgz0UzDKL EPMiYsHD0dr8FayMQbfE7TpoaE8ePzg70DSksG4CrRx+UH9xzwWLE+yTT+EoHqjFXsLj Akw9tdZsbp6tdR7NfVDWaAeiGhl1qo4gRAwxTcDmrHg1ORahgamFmiIwEDtISSKHE9I6 HCsLu0lK/LJKnrd2UOGfLFzTZ/G+Q27BSrUiLyx4AreF7RanEdxqmL/zHJRfJREQYc8m zZ9H3X5ZQU5uGGeHn9uhcGT8Kna3jAGD+Y+OTD06QNyat65TJv1eAbcXLHrBSjJsRPdR ow6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=C9sOrNkBbxcA0c7i40XbVYeVVNlHQPWI3s5+j+nAL0Y=; b=hhOEBfvDNAvpp8ZM4dbhdIFe4A9rjX6F0sFxqwkk4kcvCWhfFnELI4Mv0ZoWaTRPgE 4WTwygIw9AA9CdI5LEw9KSes2CLkijsxSp/ZJb34Bzv9cvtQfKPAEp9IB8N7J0f8ptv1 4Wv8qeJnKnUaa4HwPMBaIMDNXc6nxTu1Zn6+HEugqngw/EKIFPWx8o/IN8m1YSk8Lrm5 FoekE3a9JQYDARSNki9EQM5SlfYZJA0fvDJRJijWg1mag08cOn8r28tC2B/k9bD4fycm CitIzXGznal2rYcuVD44o8ulSw4i4/SPuLOCTOpPiguMS8yExk6imBRwQGK6TM2bpSAl 0FUw== X-Gm-Message-State: AMCzsaWL7i2U9QBnBblCr5F8yppsqKvP0P3FqQLcjgGvUpLwKqLd6NY3 /QiShZYpyinnIu8DBIfEUbsg5s89HyDKLAfVzBK1Tg== X-Google-Smtp-Source: ABhQp+SDec3IoIPO9HRPmK72ILkLu5Crw+SC764ulQBk8SapQ1DCn7PXKSZQsENAuOKMVuWXZKJwftyeUF0OxLt96XY= X-Received: by 10.223.170.67 with SMTP id q3mr4046682wrd.193.1509002524431; Thu, 26 Oct 2017 00:22:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.146.7 with HTTP; Thu, 26 Oct 2017 00:21:24 -0700 (PDT) From: Pavel Stehule Date: Thu, 26 Oct 2017 09:21:24 +0200 Message-ID: Subject: proposal: schema variables To: PostgreSQL Hackers Content-Type: multipart/alternative; boundary="94eb2c1cc5c86f1960055c6e07d9" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --94eb2c1cc5c86f1960055c6e07d9 Content-Type: text/plain; charset="UTF-8" Hi, I propose a new database object - a variable. The variable is persistent object, that holds unshared session based not transactional in memory value of any type. Like variables in any other languages. The persistence is required for possibility to do static checks, but can be limited to session - the variables can be temporal. My proposal is related to session variables from Sybase, MSSQL or MySQL (based on prefix usage @ or @@), or package variables from Oracle (access is controlled by scope), or schema variables from DB2. Any design is coming from different sources, traditions and has some advantages or disadvantages. The base of my proposal is usage schema variables as session variables for stored procedures. It should to help to people who try to port complex projects to PostgreSQL from other databases. The Sybase (T-SQL) design is good for interactive work, but it is weak for usage in stored procedures - the static check is not possible. Is not possible to set some access rights on variables. The ADA design (used on Oracle) based on scope is great, but our environment is not nested. And we should to support other PL than PLpgSQL more strongly. There is not too much other possibilities - the variable that should be accessed from different PL, different procedures (in time) should to live somewhere over PL, and there is the schema only. The variable can be created by CREATE statement: CREATE VARIABLE public.myvar AS integer; CREATE VARIABLE myschema.myvar AS mytype; CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type [ DEFAULT expression ] [[NOT] NULL] [ ON TRANSACTION END { RESET | DROP } ] [ { VOLATILE | STABLE } ]; It is dropped by command DROP VARIABLE [ IF EXISTS] varname. The access rights is controlled by usual access rights - by commands GRANT/REVOKE. The possible rights are: READ, WRITE The variables can be modified by SQL command SET (this is taken from standard, and it natural) SET varname = expression; Unfortunately we use the SET command for different purpose. But I am thinking so we can solve it with few tricks. The first is moving our GUC to pg_catalog schema. We can control the strictness of SET command. In one variant, we can detect custom GUC and allow it, in another we can disallow a custom GUC and allow only schema variables. A new command LET can be alternative. The variables should be used in queries implicitly (without JOIN) SELECT varname; The SEARCH_PATH is used, when varname is located. The variables can be used everywhere where query parameters are allowed. I hope so this proposal is good enough and simple. Comments, notes? regards Pavel --94eb2c1cc5c86f1960055c6e07d9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I propose a=C2=A0 new database object - a= variable. The variable is persistent object, that holds unshared session b= ased not transactional in memory value of any type. Like variables in any o= ther languages. The persistence is required for possibility to do static ch= ecks, but can be limited to session - the variables can be temporal.
My proposal is related to session variables from Sybase, MSSQL or M= ySQL (based on prefix usage @ or @@), or package variables from Oracle (acc= ess is controlled by scope), or schema variables from DB2. Any design is co= ming from different sources, traditions and has some advantages or disadvan= tages. The base of my proposal is usage schema variables as session variabl= es for stored procedures. It should to help to people who try to port compl= ex projects to PostgreSQL from other databases.

The Sybase=C2= =A0 (T-SQL) design is good for interactive work, but it is weak for usage i= n stored procedures - the static check is not possible. Is not possible to = set some access rights on variables.

The ADA design (used on O= racle) based on scope is great, but our environment is not nested. And we s= hould to support other PL than PLpgSQL more strongly.

There i= s not too much other possibilities - the variable that should be accessed f= rom different PL, different procedures (in time) should to live somewhere o= ver PL, and there is the schema only.

The variable can be cre= ated by CREATE statement:

CREATE VARIABLE public.myvar AS inte= ger;
CREATE VARIABLE myschema.myvar AS mytype;

CREATE= [TEMP] VARIABLE [IF NOT EXISTS] name AS type
=C2=A0 [ DEFAULT ex= pression ] [[NOT] NULL]
=C2=A0 [ ON TRANSACTION END { RESET | DRO= P } ]
=C2=A0 [ { VOLATILE | STABLE } ];

I= t is dropped by command DROP VARIABLE=C2=A0 [ IF EXISTS] varname.

The access rights is controlled by usual access rights - by commands GR= ANT/REVOKE. The possible rights are: READ, WRITE

The variables= can be modified by SQL command SET (this is taken from standard, and it na= tural)

SET varname =3D expression;

Unfortunately = we use the SET command for different purpose. But I am thinking so we can s= olve it with few tricks. The first is moving our GUC to pg_catalog schema. = We can control the strictness of SET command. In one variant, we can detect= custom GUC and allow it, in another we can disallow a custom GUC and allow= only schema variables. A new command LET can be alternative.

<= /div>
The variables should be used in queries implicitly (without JOIN)=

SELECT varname;

The SEAR= CH_PATH is used, when varname is located. The variables can be used everywh= ere where query parameters are allowed.

I hope= so this proposal is good enough and simple.

Comme= nts, notes?

regards

Pavel=


--94eb2c1cc5c86f1960055c6e07d9--