Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eEDfb-0004Cw-BF for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Nov 2017 12:16:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eEDfZ-0006AD-BL for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Nov 2017 12:16:53 +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 1eEDdv-0003Ix-6s for pgsql-hackers@postgresql.org; Mon, 13 Nov 2017 12:15:11 +0000 Received: from mail-lf0-x236.google.com ([2a00:1450:4010:c07::236]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eEDdo-000082-FP for pgsql-hackers@postgresql.org; Mon, 13 Nov 2017 12:15:10 +0000 Received: by mail-lf0-x236.google.com with SMTP id 73so3740807lfu.10 for ; Mon, 13 Nov 2017 04:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gf-microolap-com.20150623.gappssmtp.com; s=20150623; h=sender:from:date:reply-to:organization:message-id:to:subject :in-reply-to:references:mime-version:content-transfer-encoding; bh=4WK7asnN4ebZ1pGGRAkJ8MJka+HdPrVgmp/P551QMJ8=; b=CV04vfCN5J6nP2Bo2B465f0KvVh9W6/SmFXiL45lMGTUKyuBojeZb5+7ITQam5IFFK ojYg/IOmiFTABrF2sUu99lRD56F6KAD6uB9LcA0YWZHc8gcb1UuauvVdhT1u85NpUePu Y/M18qdpNnfkMyiBZl8m7aNfyBg8qjsi4PTmfrFbk9fUHrPxTUxK7ZaPKTEqBkOcWFIY 7KuvGPy0EksSa6WWYOivA703OFwChJG/9tkjuJAAr+RRci1JwevHmp9e0LFQkCI7DD+x A79EloEKaCZnW64AYneWelJqynJ5PUQrbYYfl3CEjc3Lda8MnmytqnGek+pjEWwP/9it r0Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:reply-to:organization :message-id:to:subject:in-reply-to:references:mime-version :content-transfer-encoding; bh=4WK7asnN4ebZ1pGGRAkJ8MJka+HdPrVgmp/P551QMJ8=; b=hyUP8QqN1aA7darkVyNEZopm0A/fuiD6kwpvt6+SLUon9ICyVAO8G21IvHC00dsEqF dN0q9qmPlqBf6vLTINmRV8FQkkNXVTgxSRK0XGXAZJjB3WY1UhGyGSrq/g1Ff3CCozPy FEOsgktHMH7WH0b5yFkT/wnZs31m4PIpI3TKXqteplnAWSdFMoDGmqiN/gDVgMG4dI85 BDuKiRrEnkiZBbnl89KTl7NOm9GQxG4/32b/LXFSf3TPOr6hrH65dBNWpBTGiU21hpVb NOKhtvUI51nk4k/5gHRU3sTpooUCqv6RPTkfERbt5udtTlY8/OPmC/7aFbI2jTqim6+y RNfA== X-Gm-Message-State: AJaThX7ZR2axMZKA7eMESVjZmNBfQoSAtnQRdyjqH9FKBjxidkvYAqw0 OyOG3JXdhaXvAUvc8FU2rDkviA== X-Google-Smtp-Source: AGs4zMYh0w4XJc8EeB91BcGifElR0SSCwL58659tDErFiwAu3dNvxzhLvhOtO7yFRiSBjBiSAxuJYw== X-Received: by 10.46.117.24 with SMTP id q24mr3074582ljc.14.1510575302876; Mon, 13 Nov 2017 04:15:02 -0800 (PST) Received: from u1.101.seti.kr.ua ([91.226.58.191]) by smtp.gmail.com with ESMTPSA id z81sm2840516lff.16.2017.11.13.04.15.01 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Nov 2017 04:15:01 -0800 (PST) From: Pavel Golub X-Google-Original-From: Pavel Golub Date: Mon, 13 Nov 2017 14:15:00 +0200 Reply-To: Pavel Golub Organization: Microolap Message-ID: <623395617.20171113141500@gf.microolap.com> To: Pavel Stehule , PostgreSQL Hackers Subject: Re: proposal: schema variables In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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 Hello, Pavel. You wrote: PS> Hi, PS> I propose a  new database object - a variable. The variable is PS> persistent object, that holds unshared session based not PS> transactional in memory value of any type. Like variables in any PS> other languages. The persistence is required for possibility to do PS> static checks, but can be limited to session - the variables can be temporal. Great idea. PS> My proposal is related to session variables from Sybase, MSSQL or PS> MySQL (based on prefix usage @ or @@), or package variables from PS> Oracle (access is controlled by scope), or schema variables from PS> DB2. Any design is coming from different sources, traditions and PS> has some advantages or disadvantages. The base of my proposal is PS> usage schema variables as session variables for stored procedures. PS> It should to help to people who try to port complex projects to PostgreSQL from other databases. PS> The Sybase  (T-SQL) design is good for interactive work, but it PS> is weak for usage in stored procedures - the static check is not PS> possible. Is not possible to set some access rights on variables. PS> The ADA design (used on Oracle) based on scope is great, but our PS> environment is not nested. And we should to support other PL than PLpgSQL more strongly. PS> There is not too much other possibilities - the variable that PS> should be accessed from different PL, different procedures (in PS> time) should to live somewhere over PL, and there is the schema only. PS> The variable can be created by CREATE statement: PS> CREATE VARIABLE public.myvar AS integer; PS> CREATE VARIABLE myschema.myvar AS mytype; PS> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type PS>   [ DEFAULT expression ] [[NOT] NULL] PS>   [ ON TRANSACTION END { RESET | DROP } ] PS>   [ { VOLATILE | STABLE } ]; PS> It is dropped by command DROP VARIABLE  [ IF EXISTS] varname. PS> The access rights is controlled by usual access rights - by PS> commands GRANT/REVOKE. The possible rights are: READ, WRITE PS> The variables can be modified by SQL command SET (this is taken from standard, and it natural) PS> SET varname = expression; I propose LET keyword for this to distinguish GUC from variables, e.g. LET varname = expression; PS> Unfortunately we use the SET command for different purpose. But I PS> am thinking so we can solve it with few tricks. The first is PS> moving our GUC to pg_catalog schema. We can control the strictness PS> of SET command. In one variant, we can detect custom GUC and allow PS> it, in another we can disallow a custom GUC and allow only schema PS> variables. A new command LET can be alternative. PS> The variables should be used in queries implicitly (without JOIN) PS> SELECT varname; PS> The SEARCH_PATH is used, when varname is located. The variables PS> can be used everywhere where query parameters are allowed. PS> I hope so this proposal is good enough and simple. PS> Comments, notes? PS> regards PS> Pavel -- With best wishes, Pavel mailto:pavel@gf.microolap.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers