Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 37f1be5

Browse files
author
Commitfest Bot
committed
[CF 1608] v20250515 - declarative session variables, LET command
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/1608 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAFj8pRCEjG005L=1vGbir-odYdcYxByOAeFVJ_K9eRcRF=MbNQ@mail.gmail.com Author(s): Pavel Stehule
2 parents 470273d + 46bb3e1 commit 37f1be5

File tree

117 files changed

+9966
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+9966
-64
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
<entry><link linkend="catalog-pg-user-mapping"><structname>pg_user_mapping</structname></link></entry>
370370
<entry>mappings of users to foreign servers</entry>
371371
</row>
372+
373+
<row>
374+
<entry><link linkend="catalog-pg-variable"><structname>pg_variable</structname></link></entry>
375+
<entry>session variables</entry>
376+
</row>
372377
</tbody>
373378
</tgroup>
374379
</table>
@@ -3362,6 +3367,7 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
33623367
<literal>T</literal> = type,
33633368
<literal>n</literal> = schema,
33643369
<literal>L</literal> = large object
3370+
<literal>V</literal> = session variable
33653371
</para></entry>
33663372
</row>
33673373

@@ -9779,4 +9785,132 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
97799785
</table>
97809786
</sect1>
97819787

9788+
<sect1 id="catalog-pg-variable">
9789+
<title><structname>pg_variable</structname></title>
9790+
9791+
<indexterm zone="catalog-pg-variable">
9792+
<primary>pg_variable</primary>
9793+
</indexterm>
9794+
9795+
<para>
9796+
The catalog <structname>pg_variable</structname> stores information about
9797+
session variables.
9798+
</para>
9799+
9800+
<table>
9801+
<title><structname>pg_variable</structname> Columns</title>
9802+
<tgroup cols="1">
9803+
<thead>
9804+
<row>
9805+
<entry role="catalog_table_entry"><para role="column_definition">
9806+
Column Type
9807+
</para>
9808+
<para>
9809+
Description
9810+
</para></entry>
9811+
</row>
9812+
</thead>
9813+
9814+
<tbody>
9815+
<row>
9816+
<entry role="catalog_table_entry"><para role="column_definition">
9817+
<structfield>oid</structfield> <type>oid</type>
9818+
</para>
9819+
<para>
9820+
Row identifier
9821+
</para></entry>
9822+
</row>
9823+
9824+
<row>
9825+
<entry role="catalog_table_entry"><para role="column_definition">
9826+
<structfield>vartype</structfield> <type>oid</type>
9827+
(references <link linkend="catalog-pg-type"><structname>pg_type</structname></link>.<structfield>oid</structfield>)
9828+
</para>
9829+
<para>
9830+
The OID of the variable's data type
9831+
</para></entry>
9832+
</row>
9833+
9834+
<row>
9835+
<entry role="catalog_table_entry"><para role="column_definition">
9836+
<structfield>varcreate_lsn</structfield> <type>pg_lsn</type>
9837+
</para>
9838+
<para>
9839+
LSN of the transaction where the variable was created.
9840+
<structfield>varcreate_lsn</structfield> and
9841+
<structfield>oid</structfield> together form the all-time unique
9842+
identifier (<structfield>oid</structfield> alone is not enough, since
9843+
object identifiers can get reused).
9844+
</para></entry>
9845+
</row>
9846+
9847+
<row>
9848+
<entry role="catalog_table_entry"><para role="column_definition">
9849+
<structfield>varname</structfield> <type>name</type>
9850+
</para>
9851+
<para>
9852+
Name of the session variable
9853+
</para></entry>
9854+
</row>
9855+
9856+
<row>
9857+
<entry role="catalog_table_entry"><para role="column_definition">
9858+
<structfield>varnamespace</structfield> <type>oid</type>
9859+
(references <link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link>.<structfield>oid</structfield>)
9860+
</para>
9861+
<para>
9862+
The OID of the namespace that contains this variable
9863+
</para></entry>
9864+
</row>
9865+
9866+
<row>
9867+
<entry role="catalog_table_entry"><para role="column_definition">
9868+
<structfield>varowner</structfield> <type>oid</type>
9869+
(references <link linkend="catalog-pg-authid"><structname>pg_authid</structname></link>.<structfield>oid</structfield>)
9870+
</para>
9871+
<para>
9872+
Owner of the variable
9873+
</para></entry>
9874+
</row>
9875+
9876+
<row>
9877+
<entry role="catalog_table_entry"><para role="column_definition">
9878+
<structfield>vartypmod</structfield> <type>int4</type>
9879+
</para>
9880+
<para>
9881+
<structfield>vartypmod</structfield> records type-specific data
9882+
supplied at variable creation time (for example, the maximum
9883+
length of a <type>varchar</type> column). It is passed to
9884+
type-specific input functions and length coercion functions.
9885+
The value will generally be -1 for types that do not need <structfield>vartypmod</structfield>.
9886+
</para></entry>
9887+
</row>
9888+
9889+
<row>
9890+
<entry role="catalog_table_entry"><para role="column_definition">
9891+
<structfield>varcollation</structfield> <type>oid</type>
9892+
(references <link linkend="catalog-pg-collation"><structname>pg_collation</structname></link>.<structfield>oid</structfield>)
9893+
</para>
9894+
<para>
9895+
The defined collation of the variable, or zero if the variable is
9896+
not of a collatable data type.
9897+
</para></entry>
9898+
</row>
9899+
9900+
<row>
9901+
<entry role="catalog_table_entry"><para role="column_definition">
9902+
<structfield>varacl</structfield> <type>aclitem[]</type>
9903+
</para>
9904+
<para>
9905+
Access privileges; see
9906+
<xref linkend="sql-grant"/> and
9907+
<xref linkend="sql-revoke"/>
9908+
for details
9909+
</para></entry>
9910+
</row>
9911+
9912+
</tbody>
9913+
</tgroup>
9914+
</table>
9915+
</sect1>
97829916
</chapter>

doc/src/sgml/config.sgml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11374,6 +11374,131 @@ dynamic_library_path = '/usr/local/lib/postgresql:$libdir'
1137411374
</listitem>
1137511375
</varlistentry>
1137611376

11377+
<varlistentry id="guc-session-variables-ambiguity-warning" xreflabel="session_variables_ambiguity_warning">
11378+
<term><varname>session_variables_ambiguity_warning</varname> (<type>boolean</type>)
11379+
<indexterm>
11380+
<primary><varname>session_variables_ambiguity_warning</varname> configuration parameter</primary>
11381+
</indexterm>
11382+
</term>
11383+
<listitem>
11384+
<para>
11385+
When on, a warning is raised when any identifier in a query could be
11386+
used as both a column identifier, routine variable or a session
11387+
variable identifier. The default is <literal>off</literal>.
11388+
</para>
11389+
<para>
11390+
Session variables can be shadowed by column references in a query, this
11391+
is an expected behavior. Previously working queries shouldn't error out
11392+
by creating any session variable, so session variables are always shadowed
11393+
if an identifier is ambiguous. Variables should be referenced using
11394+
anunambiguous identifier without any possibility for a collision with
11395+
identifier of other database objects (column names or record fields names).
11396+
The warning messages emitted when enabling <varname>session_variables_ambiguity_warning</varname>
11397+
can help finding such identifier collision.
11398+
<programlisting>
11399+
CREATE TABLE foo(a int);
11400+
INSERT INTO foo VALUES(10);
11401+
CREATE VARIABLE a int;
11402+
LET a = 100;
11403+
SELECT a FROM foo;
11404+
</programlisting>
11405+
11406+
<screen>
11407+
a
11408+
----
11409+
10
11410+
(1 row)
11411+
</screen>
11412+
11413+
<programlisting>
11414+
SET session_variables_ambiguity_warning TO on;
11415+
SELECT a FROM foo;
11416+
</programlisting>
11417+
11418+
<screen>
11419+
WARNING: session variable "a" is shadowed
11420+
LINE 1: SELECT a FROM foo;
11421+
^
11422+
DETAIL: Session variables can be shadowed by columns, routine's variables and routine's arguments with the same name.
11423+
a
11424+
----
11425+
10
11426+
(1 row)
11427+
</screen>
11428+
</para>
11429+
<para>
11430+
This feature can significantly increase log size, so it's disabled by
11431+
default. For testing or development environments it's recommended to
11432+
enable it if you use session variables.
11433+
</para>
11434+
</listitem>
11435+
</varlistentry>
11436+
11437+
<varlistentry id="guc-session-variables-use-fence-warning-guard" xreflabel="session_variables_use_fence_warning_guard">
11438+
<term><varname>session_variables_use_fence_warning_guard</varname> (<type>boolean</type>)
11439+
<indexterm>
11440+
<primary><varname>session_variables_use_fence_warning_guard</varname> configuration parameter</primary>
11441+
</indexterm>
11442+
</term>
11443+
<listitem>
11444+
<para>
11445+
When on, a warning is raised when a session variable identifier is used
11446+
inside a query without variable fence. The default is <literal>off</literal>.
11447+
The warning is raised only when variable is used in places, where an
11448+
collisions with column names is possible.
11449+
<programlisting>
11450+
CREATE TABLE foo(a int);
11451+
INSERT INTO foo VALUES(10);
11452+
CREATE VARIABLE b int;
11453+
LET b = 100;
11454+
SELECT a, b FROM foo;
11455+
</programlisting>
11456+
11457+
<screen>
11458+
a | b
11459+
----+-----
11460+
10 | 100
11461+
(1 row)
11462+
</screen>
11463+
11464+
<programlisting>
11465+
SET session_variables_use_fence_warning_guard TO on;
11466+
SELECT a, b FROM foo;
11467+
</programlisting>
11468+
11469+
<screen>
11470+
WARNING: session variable "b" is not used inside variable fence
11471+
LINE 1: SELECT a, b FROM foo;
11472+
^
11473+
DETAIL: The collision of session variable' names and column names is possible.
11474+
a | b
11475+
----+-----
11476+
10 | 100
11477+
(1 row)
11478+
</screen>
11479+
11480+
<programlisting>
11481+
SELECT a, VARIABLE(b) FROM foo;
11482+
</programlisting>
11483+
11484+
<screen>
11485+
a | b
11486+
----+-----
11487+
10 | 100
11488+
(1 row)
11489+
</screen>
11490+
</para>
11491+
11492+
<para>
11493+
This feature can significantly increase log size, so it's disabled by
11494+
default. Unless another collision resolution technique is used
11495+
(dedicated schema or using prefixes like <literal>_</literal>),
11496+
the use of variable fence syntax is strongly recommended, and this
11497+
warning should be enabled.
11498+
</para>
11499+
</listitem>
11500+
</varlistentry>
11501+
1137711502
<varlistentry id="guc-standard-conforming-strings" xreflabel="standard_conforming_strings">
1137811503
<term><varname>standard_conforming_strings</varname> (<type>boolean</type>)
1137911504
<indexterm><primary>strings</primary><secondary>standard conforming</secondary></indexterm>

0 commit comments

Comments
 (0)