Re: proposal: schema variables

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-19 19:14:01
Message-ID: CAFj8pRB_E1GM_YGT-ti4bXka6mhLdAAFeTe+BHgHFYC+qb-76g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

Hi

I wrote POC of VARIABLE(varname) syntax support

here is a copy from regress test

SET session_variables_ambiguity_warning TO on;
SET session_variables_use_fence_warning_guard TO on;
SET search_path TO 'public';
CREATE VARIABLE a AS int;
LET a = 10;
CREATE TABLE test_table(a int, b int);
INSERT INTO test_table VALUES(20, 20);
-- no warning
SELECT a;
a..
----
10
(1 row)

-- warning variable is shadowed
SELECT a, b FROM test_table;
WARNING: session variable "a" is shadowed
LINE 1: SELECT a, b FROM test_table;
^
DETAIL: Session variables can be shadowed by columns, routine's variables
and routine's arguments with the same name.
a | b..
----+----
20 | 20
(1 row)

-- no warning
SELECT variable(a) FROM test_table;
a..
----
10
(1 row)

ALTER TABLE test_table DROP COLUMN a;
-- warning - variable fence is not used
SELECT a, b FROM test_table;
WARNING: session variable "a" is not used inside variable fence
LINE 1: SELECT a, b FROM test_table;
^
DETAIL: The collision of session variable' names and column names is
possible.
a | b..
----+----
10 | 20
(1 row)

-- no warning
SELECT variable(a), b FROM test_table;
a | b..
----+----
10 | 20
(1 row)

DROP VARIABLE a;
DROP TABLE test_table;
SET session_variables_ambiguity_warning TO DEFAULT;
SET session_variables_use_fence_warning_guard TO DEFAULT;
SET search_path TO DEFAULT;

Regards

Pavel

Attachment Content-Type Size
0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
0019-transactional-variables.patch text/x-patch 39.2 KB
0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
0021-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 14.7 KB
0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
0010-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
0006-plpgsql-tests.patch text/x-patch 16.9 KB
0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message James Coleman 2024-11-19 19:16:59 Parallel safety docs for CTEs
Previous Message Peter Geoghegan 2024-11-19 19:06:35 Re: Adding skip scan (including MDAM style range skip scan) to nbtree

Browse pgsql-performance by date

  From Date Subject
Next Message Pavel Stehule 2024-11-19 21:30:00 Re: proposal: schema variables
Previous Message Pavel Stehule 2024-11-17 04:53:17 Re: proposal: schema variables