From 600873a89e76124f294b096a824d6fd4e24c4a28 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Wed, 26 Jan 2022 15:03:27 +0800 Subject: [PATCH v20220126 3/3] Various fixes. --- doc/src/sgml/advanced.sgml | 35 +++++---- doc/src/sgml/catalogs.sgml | 4 +- doc/src/sgml/config.sgml | 6 +- doc/src/sgml/glossary.sgml | 12 +-- doc/src/sgml/plpgsql.sgml | 11 ++- .../sgml/ref/alter_default_privileges.sgml | 16 ++-- doc/src/sgml/ref/alter_variable.sgml | 44 +++++------ doc/src/sgml/ref/create_variable.sgml | 75 ++++++++++--------- doc/src/sgml/ref/discard.sgml | 4 +- doc/src/sgml/ref/drop_variable.sgml | 18 ++--- doc/src/sgml/ref/let.sgml | 8 +- doc/src/sgml/ref/pg_restore.sgml | 4 +- src/backend/catalog/namespace.c | 7 +- src/backend/catalog/pg_variable.c | 16 ++-- src/backend/commands/sessionvariable.c | 2 +- src/backend/executor/svariableReceiver.c | 2 +- src/include/catalog/pg_variable.h | 2 +- src/include/commands/session_variable.h | 2 +- src/include/executor/svariableReceiver.h | 2 +- 19 files changed, 140 insertions(+), 130 deletions(-) diff --git a/doc/src/sgml/advanced.sgml b/doc/src/sgml/advanced.sgml index 97470521a8..c50c2ff880 100644 --- a/doc/src/sgml/advanced.sgml +++ b/doc/src/sgml/advanced.sgml @@ -714,16 +714,18 @@ SELECT name, elevation Session variables are database objects that can hold a value. - Session variables, like relations, exist within a schema and their access is - controlled via GRANT and REVOKE commands. - A session variable can be created by the CREATE VARIABLE command. + Session variables, like relations, exist within a schema and their access + is controlled via GRANT and REVOKE + commands. A session variable can be created by the CREATE + VARIABLE command. - The value of a session variable is set with the LET SQL command. - While session variables share properties with tables, their value cannot be updated - with an UPDATE command. The value of a session variable may be - retrieved by the SELECT SQL command. + The value of a session variable is set with the LET SQL + command. While session variables share properties with tables, their value + cannot be updated with an UPDATE command. The value of a + session variable may be retrieved by the SELECT SQL + command. CREATE VARIABLE var1 AS date; LET var1 = current_date; @@ -742,18 +744,19 @@ SELECT current_user_id; The value of a session variable is local to the current session. Retrieving - a variable's value returns either a NULL or a default value, - unless its value is set to something else in the current session using the - LET command. The content of a variable is not transactional. - This is the same as regular variables in PL languages. + a variable's value returns either a NULL or a default + value, unless its value has been set to something else in the current + session using the LET command. The content of a variable + is not transactional. This is the same as regular variables in PL + languages. - The session variables can be shadowed by column references in a query. When a - query contains identifiers or qualified identifiers that could be used as both - a session variable identifiers and as column identifier, then the column - identifier is preferred every time. Warnings can be emitted when this situation - happens by enabling configuration parameter . diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index db805fe079..a85571c1a7 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -14001,8 +14001,8 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx - The table pg_variable provides information - about session variables. + The table pg_variable provides information about + session variables. diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 8990337f81..7a39da0e74 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -10031,9 +10031,9 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' - When on, a warning is raised when any identifier in a query could be used as both - a column identifier, routine variable or a session variable identifier. - The default is off. + When on, a warning is raised when any identifier in a query could be + used as both a column identifier, routine variable or a session + variable identifier. The default is off. diff --git a/doc/src/sgml/glossary.sgml b/doc/src/sgml/glossary.sgml index 641dcc67b3..2529805ab4 100644 --- a/doc/src/sgml/glossary.sgml +++ b/doc/src/sgml/glossary.sgml @@ -1467,14 +1467,14 @@ Session variable - A persistent database object that holds a value in session memory. - This memory is not shared across sessions, and after session end, this - memory (the value) is released. The access (read or write) to session variables - is controlled by access rights similarly to other database object access rights. + A persistent database object that holds a value in session memory. This + memory is not shared across sessions, and after session end, this memory + (the value) is released. The access (read or write) to session variables + is controlled by access rights similarly to other database object access + rights. - For more information, see - . + For more information, see . diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 423677b9af..9569f2c0e4 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -5957,12 +5957,11 @@ $$ LANGUAGE plpgsql STRICT IMMUTABLE; <command>Session variables and constants</command> - The PL/pgSQL language has no packages, - and therefore no package variables or package constants. - PostgreSQL has session variables and - immutable session variables. Session variables can be created - by CREATE VARIABLE described in . + The PL/pgSQL language has no packages, and + therefore no package variables or package constants. + PostgreSQL has session variables and immutable + session variables. Session variables can be created by CREATE + VARIABLE, as described in . diff --git a/doc/src/sgml/ref/alter_default_privileges.sgml b/doc/src/sgml/ref/alter_default_privileges.sgml index 7eb1e8cf8b..ec85fa39cf 100644 --- a/doc/src/sgml/ref/alter_default_privileges.sgml +++ b/doc/src/sgml/ref/alter_default_privileges.sgml @@ -102,14 +102,14 @@ REVOKE [ GRANT OPTION FOR ] that will be applied to objects created in the future. (It does not affect privileges assigned to already-existing objects.) Currently, only the privileges for schemas, tables (including views and foreign - tables), sequences, functions, types (including domains) and session variables - can be altered. For this command, functions include aggregates and procedures. - The words FUNCTIONS and ROUTINES are - equivalent in this command. (ROUTINES is preferred - going forward as the standard term for functions and procedures taken - together. In earlier PostgreSQL releases, only the - word FUNCTIONS was allowed. It is not possible to set - default privileges for functions and procedures separately.) + tables), sequences, functions, types (including domains) and session + variables can be altered. For this command, functions include aggregates + and procedures. The words FUNCTIONS and + ROUTINES are equivalent in this command. + (ROUTINES is preferred going forward as the standard term + for functions and procedures taken together. In earlier PostgreSQL + releases, only the word FUNCTIONS was allowed. It is not + possible to set default privileges for functions and procedures separately.) diff --git a/doc/src/sgml/ref/alter_variable.sgml b/doc/src/sgml/ref/alter_variable.sgml index 50b1f6a2d7..06e7f8cd96 100644 --- a/doc/src/sgml/ref/alter_variable.sgml +++ b/doc/src/sgml/ref/alter_variable.sgml @@ -22,7 +22,7 @@ PostgreSQL documentation ALTER VARIABLE - change the definition of a variable + change the definition of a session variable @@ -38,15 +38,15 @@ ALTER VARIABLE name SET SCHEMA Description - The ALTER VARIABLE command changes the definition of an existing - variable. There are several subforms: + The ALTER VARIABLE command changes the definition of an + existing session variable. There are several subforms: OWNER - This form changes the owner of the variable. + This form changes the owner of the session variable. @@ -55,7 +55,7 @@ ALTER VARIABLE name SET SCHEMA RENAME - This form changes the name of the variable. + This form changes the name of the session variable. @@ -64,7 +64,7 @@ ALTER VARIABLE name SET SCHEMA SET SCHEMA - This form moves the variable into another schema. + This form moves the session variable into another schema. @@ -74,16 +74,16 @@ ALTER VARIABLE name SET SCHEMA Only the owner or a superuser is allowed to alter a session variable. - In order to move a session variable from one schema to another, the user must - also have the CREATE privilege on the new schema (or be - a superuser). + In order to move a session variable from one schema to another, the user + must also have the CREATE privilege on the new schema (or + be a superuser). In order to move the session variable ownership from one role to another, the user must also be a direct or indirect member of the new owning role, and that role must have the CREATE privilege - on the variable's schema (or be a superuser). These restrictions enforce that - altering the owner doesn't do anything you couldn't do by dropping and - recreating the variable. + on the session variable's schema (or be a superuser). These restrictions + enforce that altering the owner doesn't do anything you couldn't do by + dropping and recreating the session variable. @@ -96,8 +96,8 @@ ALTER VARIABLE name SET SCHEMA name - The name (possibly schema-qualified) of the existing variable to - alter. + The name (possibly schema-qualified) of the existing session variable + to alter. @@ -106,7 +106,7 @@ ALTER VARIABLE name SET SCHEMA new_name - The new name for the variable. + The new name for the session variable. @@ -115,7 +115,7 @@ ALTER VARIABLE name SET SCHEMA new_owner - The user name of the new owner of the variable. + The user name of the new owner of the session variable. @@ -124,7 +124,7 @@ ALTER VARIABLE name SET SCHEMA new_schema - The new schema for the variable. + The new schema for the session variable. @@ -136,23 +136,23 @@ ALTER VARIABLE name SET SCHEMA Examples - To rename a variable: + To rename a session variable: ALTER VARIABLE foo RENAME TO boo; - To change the owner of the variable boo - to joe: + To change the owner of the session variable boo to + joe: ALTER VARIABLE boo OWNER TO joe; - To change the schema of the variable boo - to private: + To change the schema of the session variable boo to + private: ALTER VARIABLE boo SET SCHEMA private; diff --git a/doc/src/sgml/ref/create_variable.sgml b/doc/src/sgml/ref/create_variable.sgml index 38b8a2fbc6..04fb30873a 100644 --- a/doc/src/sgml/ref/create_variable.sgml +++ b/doc/src/sgml/ref/create_variable.sgml @@ -36,22 +36,23 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] The CREATE VARIABLE command creates a session variable. Session variables, like relations, exist within a schema and their access is - controlled via GRANT and REVOKE commands. - Changing a session variable is non-transactional. + controlled via GRANT and REVOKE + commands. Changing a session variable is non-transactional. The value of a session variable is local to the current session. Retrieving - a variable's value returns either a NULL or a default value, unless its value - is set to something else in the current session with a LET command. The content - of a variable is not transactional. This is the same as regular variables in PL languages. + a session variable's value returns either a NULL or a default value, unless + its value is set to something else in the current session with a LET + command. The content of a session variable is not transactional. This is the + same as regular variables in PL languages. - Session variables are retrieved by the SELECT SQL command. - Their value is set with the LET SQL command. - While session variables share properties with tables, their value cannot be updated - with an UPDATE command. + Session variables are retrieved by the SELECT SQL + command. Their value is set with the LET SQL command. + While session variables share properties with tables, their value cannot be + changed with an UPDATE command. @@ -63,10 +64,10 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] IMMUTABLE - The assigned value of the variable cannot be changed. The value can be assigned - by command LET only first time (when session variable has not - defined default expression), or never (when session variable has defined not null - default expression). + The assigned value of the session variable can never change. + If the session variable doesn't have a default value, then a single + initialization is allowed using the LET command. Once + done, no other change will be allowed in the session lifetime. @@ -75,7 +76,8 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] IF NOT EXISTS - Do not throw an error if the name already exists. A notice is issued in this case. + Do not throw an error if the name already exists. A notice is issued in + this case. @@ -84,7 +86,7 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] name - The name, optionally schema-qualified, of the variable. + The name, optionally schema-qualified, of the session variable. @@ -93,7 +95,8 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] data_type - The name, optionally schema-qualified, of the data type of the variable. + The name, optionally schema-qualified, of the data type of the session + variable. @@ -102,9 +105,9 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] COLLATE collation - The COLLATE clause assigns a collation to - the variable (which must be of a collatable data type). - If not specified, the data type's default collation is used. + The COLLATE clause assigns a collation to the session + variable (which must be of a collatable data type). If not specified, + the data type's default collation is used. @@ -113,11 +116,12 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] NOT NULL - The NOT NULL clause forbids setting the variable to - a null value. A variable created as NOT NULL and without an explicitly - declared default value cannot be read until it is initialized by a LET - command. This requires the user to explicitly initialize the variable - content before reading it. + The NOT NULL clause forbids setting the session + variable to a null value. A session variable created as NOT NULL and + without an explicitly declared default value cannot be read until it is + initialized by a LET command. This requires the user to explicitly + initialize the session variable content before reading it, otherwise an + error will be thrown. @@ -126,8 +130,8 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] DEFAULT default_expr - The DEFAULT clause can be used to assign a default value to - a session variable. + The DEFAULT clause can be used to assign a default + value to a session variable. @@ -136,11 +140,11 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] ON COMMIT DROP, ON TRANSACTION END RESET - The ON COMMIT DROP clause specifies the behaviour - of a temporary session variable at transaction commit. With this clause, the -      variable is dropped at commit time. The clause is only allowed -      for temporary variables. The ON TRANSACTION END RESET - clause causes the variable to be reset to its default value when + The ON COMMIT DROP clause specifies the behaviour of a + temporary session variable at transaction commit. With this clause, the + session variable is dropped at commit time. The clause is only allowed + for temporary variables. The ON TRANSACTION END RESET + clause causes the session variable to be reset to its default value when the transaction is committed or rolled back. @@ -153,7 +157,8 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] Notes - Use the DROP VARIABLE command to remove a variable. + Use the DROP VARIABLE command to remove a session + variable. @@ -161,7 +166,7 @@ CREATE [ { TEMPORARY | TEMP } ] [ IMMUTABLE ] VARIABLE [ IF NOT EXISTS ] Examples - Create an integer variable var1: + Create an date session variable var1: CREATE VARIABLE var1 AS date; LET var1 = current_date; @@ -175,8 +180,8 @@ SELECT var1; Compatibility - The CREATE VARIABLE command is a PostgreSQL extension. - + The CREATE VARIABLE command is a + PostgreSQL extension. diff --git a/doc/src/sgml/ref/discard.sgml b/doc/src/sgml/ref/discard.sgml index 48d96af187..6f90672afa 100644 --- a/doc/src/sgml/ref/discard.sgml +++ b/doc/src/sgml/ref/discard.sgml @@ -80,8 +80,8 @@ DISCARD { ALL | PLANS | SEQUENCES | TEMPORARY | TEMP | VARIABLES } Resets the value of all session variables. If a variable -      is later reused, it is re-initialized to either -      NULL or its default value. + is later reused, it is re-initialized to either + NULL or its default value. diff --git a/doc/src/sgml/ref/drop_variable.sgml b/doc/src/sgml/ref/drop_variable.sgml index 5cced4ea90..67988b5fcd 100644 --- a/doc/src/sgml/ref/drop_variable.sgml +++ b/doc/src/sgml/ref/drop_variable.sgml @@ -35,7 +35,7 @@ DROP VARIABLE [ IF EXISTS ] name [, DROP VARIABLE removes a session variable. - A variable can only be dropped by its owner or a superuser. + A session variable can only be removed by its owner or a superuser. @@ -47,8 +47,8 @@ DROP VARIABLE [ IF EXISTS ] name [, IF EXISTS - Do not throw an error if the variable does not exist. A notice is issued - in this case. + Do not throw an error if the session variable does not exist. A notice is + issued in this case. @@ -66,9 +66,8 @@ DROP VARIABLE [ IF EXISTS ] name [, CASCADE - Automatically drop objects that depend on the variable (such as - views), - and in turn all objects that depend on those objects + Automatically drop objects that depend on the session variable (such as + views), and in turn all objects that depend on those objects (see ). @@ -78,7 +77,7 @@ DROP VARIABLE [ IF EXISTS ] name [, RESTRICT - Refuse to drop the variable if any objects depend on it. This is + Refuse to drop the session variable if any objects depend on it. This is the default. @@ -101,9 +100,8 @@ DROP VARIABLE var1; Compatibility - The DROP VARIABLE command is a PostgreSQL extension. - + The DROP VARIABLE command is a + PostgreSQL extension. diff --git a/doc/src/sgml/ref/let.sgml b/doc/src/sgml/ref/let.sgml index fcbfefb4f6..cf5515ac67 100644 --- a/doc/src/sgml/ref/let.sgml +++ b/doc/src/sgml/ref/let.sgml @@ -35,7 +35,8 @@ LET session_variable = DEFAULT Description - The LET command assigns a value to the specified session variable. + The LET command assigns a value to the specified session + variable. @@ -57,7 +58,8 @@ LET session_variable = DEFAULT sql_expression - An SQL expression. The result is cast to the data type of the session variable. + An SQL expression. The result is cast to the data type of the session + variable. @@ -91,7 +93,7 @@ LET myvar = DEFAULT; LET extends the syntax defined in the SQL standard. The SET command from the SQL standard - is used for different purposes in PostgreSQL. + is used for different purposes in PostgreSQL. diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml index 3e8c26c695..85f29431c1 100644 --- a/doc/src/sgml/ref/pg_restore.sgml +++ b/doc/src/sgml/ref/pg_restore.sgml @@ -111,8 +111,8 @@ PostgreSQL documentation - Restore a named session variable only. Multiple session variables may be specified with - multiple switches. + Restore a named session variable only. Multiple session variables may + be specified with multiple switches. diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index fc0e08be46..bb95207977 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -2907,8 +2907,7 @@ TSConfigIsVisible(Oid cfgid) } /* - * Returns oid of session variable specified by possibly qualified - * identifier. + * Returns oid of session variable specified by possibly qualified identifier. * * If not found, returns InvalidOid if missing_ok, else throws error. */ @@ -2924,8 +2923,8 @@ LookupVariable(const char *nspname, const char *varname, bool missing_ok) namespaceId = LookupExplicitNamespace(nspname, missing_ok); /* - * When nspname is not known namespace, then nspname.varname - * cannot to identify any session variable. + * If nspname is not a known namespace, then nspname.varname cannot be + * any usable session variable. */ if (!OidIsValid(namespaceId)) return InvalidOid; diff --git a/src/backend/catalog/pg_variable.c b/src/backend/catalog/pg_variable.c index fa81b54f59..1f73848312 100644 --- a/src/backend/catalog/pg_variable.c +++ b/src/backend/catalog/pg_variable.c @@ -3,7 +3,7 @@ * pg_variable.c * session variables * - * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION @@ -71,8 +71,8 @@ to_eoxaction(VariableEOXActionCodes code) } /* - * Returns name of session variable. When the variable is not in the path, - * the name is qualified. + * Returns the name of a given session variable. When the variable is not in + * the path, the name is qualified. */ char * session_variable_get_name(Oid varid) @@ -129,7 +129,7 @@ get_session_variable_name(Oid varid) } /* - * Returns type, typmod and collid of session variable. + * Returns the type, typmod and collid of the given session variable. */ void get_session_variable_type_typmod_collid(Oid varid, Oid *typid, int32 *typmod, @@ -379,11 +379,15 @@ VariableCreate(const char *varName, } /* - * When this new field in catalog is temporal, we need to create - * new xact action to ensure delete from catalog. + * For temporary variables, we need to create a new end of xact action to + * ensure deletion from catalog. */ if (eoxaction == VARIABLE_EOX_DROP) + { + Assert(isTempNamespace(varNamespace)); + RegisterOnCommitDropSessionVariable(myself.objectId); + } heap_freetuple(tup); diff --git a/src/backend/commands/sessionvariable.c b/src/backend/commands/sessionvariable.c index 0e058b693e..1fc050ee80 100644 --- a/src/backend/commands/sessionvariable.c +++ b/src/backend/commands/sessionvariable.c @@ -3,7 +3,7 @@ * sessionvariable.c * session variable creation/manipulation commands * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * diff --git a/src/backend/executor/svariableReceiver.c b/src/backend/executor/svariableReceiver.c index 66b8b6ec8c..d5ce377b0f 100644 --- a/src/backend/executor/svariableReceiver.c +++ b/src/backend/executor/svariableReceiver.c @@ -4,7 +4,7 @@ * An implementation of DestReceiver that stores the result value in * a session variable. * - * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION diff --git a/src/include/catalog/pg_variable.h b/src/include/catalog/pg_variable.h index b6716ca8cc..72c9f8a3ce 100644 --- a/src/include/catalog/pg_variable.h +++ b/src/include/catalog/pg_variable.h @@ -4,7 +4,7 @@ * definition of session variables system catalog (pg_variables) * * - * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/catalog/pg_variable.h diff --git a/src/include/commands/session_variable.h b/src/include/commands/session_variable.h index c8c3ab2570..7606235afc 100644 --- a/src/include/commands/session_variable.h +++ b/src/include/commands/session_variable.h @@ -4,7 +4,7 @@ * prototypes for sessionvariable.c. * * - * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/commands/session_variable.h diff --git a/src/include/executor/svariableReceiver.h b/src/include/executor/svariableReceiver.h index 5305936547..1d823a42a8 100644 --- a/src/include/executor/svariableReceiver.h +++ b/src/include/executor/svariableReceiver.h @@ -4,7 +4,7 @@ * prototypes for svariableReceiver.c * * - * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/executor/svariableReceiver.h -- 2.33.1