Re: proposal: schema variables
Pavel Stehule <pavel.stehule@gmail.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Move WAL sequence code into its own file
- a87987cafca6 19 (unreleased) cited
-
Add ExplainState argument to pg_plan_query() and planner().
- c83ac02ec730 19 (unreleased) cited
-
Don't include access/htup_details.h in executor/tuptable.h
- 1a8b5b11e48a 19 (unreleased) cited
-
Refactor to avoid code duplication in transformPLAssignStmt.
- b0fb2c6aa5a4 19 (unreleased) cited
-
Avoid including commands/dbcommands.h in so many places
- 325fc0ab14d1 19 (unreleased) cited
-
Restrict psql meta-commands in plain-text dumps.
- 71ea0d679543 19 (unreleased) cited
-
Split func.sgml into more manageable pieces
- 4e23c9ef65ac 19 (unreleased) cited
-
Fix squashing algorithm for query texts
- 0f65f3eec478 18.0 cited
-
EXPLAIN: Always use two fractional digits for row counts.
- 95dbd827f2ed 18.0 cited
-
Preliminary refactoring of plpgsql expression construction.
- a654af21ae52 18.0 cited
-
plpgsql: pure parser and reentrant scanner
- 7b27f5fd36cb 18.0 cited
-
Add some sanity checks in executor for query ID reporting
- 24f520594809 18.0 cited
-
Fix misleading error message context
- 4af123ad45bd 18.0 cited
-
Add macros for looping through a List without a ListCell.
- 14dd0f27d7cd 17.0 cited
Attachments
- v20241208-0021-pg_restore-A-variable.patch (text/x-patch) patch v20241208-0021
- v20241208-0020-transactional-variables.patch (text/x-patch) patch v20241208-0020
- v20241208-0017-plpgsql-implementation-for-LET-statement.patch (text/x-patch) patch v20241208-0017
- v20241208-0019-this-patch-changes-error-message-column-doesn-t-exis.patch (text/x-patch) patch v20241208-0019
- v20241208-0018-expression-with-session-variables-can-be-inlined.patch (text/x-patch) patch v20241208-0018
- v20241208-0015-allow-read-an-value-of-session-variable-directly-fro.patch (text/x-patch) patch v20241208-0015
- v20241208-0016-allow-parallel-execution-queries-with-session-variab.patch (text/x-patch) patch v20241208-0016
- v20241208-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch (text/x-patch) patch v20241208-0014
- v20241208-0010-PREPARE-LET-support.patch (text/x-patch) patch v20241208-0010
- v20241208-0013-Implementation-of-DEFAULT-clause-default-expressions.patch (text/x-patch) patch v20241208-0013
- v20241208-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch (text/x-patch) patch v20241208-0012
- v20241208-0011-implementation-of-temporary-session-variables.patch (text/x-patch) patch v20241208-0011
- v20241208-0006-plpgsql-tests.patch (text/x-patch) patch v20241208-0006
- v20241208-0009-EXPLAIN-LET-support.patch (text/x-patch) patch v20241208-0009
- v20241208-0008-variable-fence-syntax-support-and-variable-fence-usa.patch (text/x-patch) patch v20241208-0008
- v20241208-0005-memory-cleaning-after-DROP-VARIABLE.patch (text/x-patch) patch v20241208-0005
- v20241208-0007-GUC-session_variables_ambiguity_warning.patch (text/x-patch) patch v20241208-0007
- v20241208-0002-Storage-for-session-variables-and-SQL-interface.patch (text/x-patch) patch v20241208-0002
- v20241208-0003-function-pg_session_variables-for-cleaning-tests.patch (text/x-patch) patch v20241208-0003
- v20241208-0004-DISCARD-VARIABLES.patch (text/x-patch) patch v20241208-0004
- v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch (text/x-patch) patch v20241208-0001
Hi
so 7. 12. 2024 v 3:13 odesílatel jian he <jian.universality@gmail.com>
napsal:
> On Thu, Dec 5, 2024 at 2:52 PM Pavel Stehule <pavel.stehule@gmail.com>
> wrote:
> >
> > Hi
> >
> > only rebase
>
> hi.
> disclaimer, i *only* applied
> v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch.
>
> create variable v2 as text;
> alter variable v2 rename to v2;
> ERROR: session variable "v2" already exists in schema "public"
>
> the above is coverage tests for report_namespace_conflict:
> case VariableRelationId:
> Assert(OidIsValid(nspOid));
> msgfmt = gettext_noop("session variable \"%s\" already
> exists in schema \"%s\"");
> break;
>
I don't understand what is an issue?
This is consistent with other database object
(2024-12-07 18:25:29) postgres=# create table foo(a int);
CREATE TABLE
(2024-12-07 18:25:35) postgres=# alter table foo rename
a COLUMN CONSTRAINT TO
(2024-12-07 18:25:35) postgres=# alter table foo rename to foo;
ERROR: relation "foo" already exists
>
> create type t1 as (a int, b int);
> CREATE VARIABLE var1 AS t1;
> alter type t1 drop attribute a;
> should "alter type t1 drop attribute a;" not allowed?
>
you can add a new attribute, or you can drop the attribute. You cannot
change the type of the attribute.
>
> GetCommandLogLevel also needs to deal with case T_CreateSessionVarStmt?
>
yes - it should be there - I fixed this + regress test
>
> there are no regress tests for the change we made in
> find_composite_type_dependencies?
> It looks like it will be reachable for sure.
>
It was tested in patch02, where the correct work with variable's values.
But I wrote few tests, that better describe this functionality and I added
to patch01
+SET log_statement TO ddl;
-- should be ok
CREATE VARIABLE var1 AS int;
-- should fail, pseudotypes are not allowed
@@ -15,6 +16,36 @@ CREATE VARIABLE var1 AS int;
ERROR: session variable "var1" already exists
-- should be ok
DROP VARIABLE IF EXISTS var1;
+-- the variable can use composite types
+CREATE TABLE t1 (a int, b int);
+CREATE VARIABLE var1 AS t1;
+-- should fail
+DROP TABLE t1;
+ERROR: cannot drop table t1 because other objects depend on it
+DETAIL: session variable var1 depends on type t1
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+-- should be ok
+ALTER TABLE t1 ADD COLUMN c int;
+-- should fail
+ALTER TABLE t1 ALTER COLUMN b TYPE numeric;
+ERROR: cannot alter table "t1" because session variable "public.var1"
uses it
+DROP VARIABLE var1;
+DROP TABLE t1;
+CREATE TYPE t1 AS (a int, b int);
+CREATE VARIABLE var1 AS t1;
+-- should fail
+DROP TYPE t1;
+ERROR: cannot drop type t1 because other objects depend on it
+DETAIL: session variable var1 depends on type t1
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+-- should be ok
+ALTER TYPE t1 ADD ATTRIBUTE c int;
+-- should fail
+ALTER TYPE t1 ALTER ATTRIBUTE b TYPE numeric;
+ERROR: cannot alter type "t1" because session variable "public.var1" uses
it
+DROP VARIABLE var1;
+DROP TYPE t1;
+SET log_statement TO default;
>
>
> CreateVariable, print out error position:
> if (get_typtype(typid) == TYPTYPE_PSEUDO)
> ereport(ERROR,
> (errcode(ERRCODE_WRONG_OBJECT_TYPE),
> errmsg("session variable cannot be pseudo-type %s",
> format_type_be(typid)),
> parser_errposition(pstate, stmt->typeName->location)));
>
> Alvaro Herrera told me actually, you don't need the extra parentheses
> around errcode.
> so you can:
> if (get_typtype(typid) == TYPTYPE_PSEUDO)
> ereport(ERROR,
> errcode(ERRCODE_WRONG_OBJECT_TYPE),
> errmsg("session variable cannot be pseudo-type %s",
> format_type_be(typid)),
> parser_errposition(pstate, stmt->typeName->location))
>
yes, it is not necessary, but it is used almost everywhere in Postgres
source code. So I prefer
to be consistent with usual ereport notation. It can be fixed later, but it
is used 7136 times in pg code.
Probably this needs a wide discussion. Without extra parenthesis the code
looks little bit nicer,
but this should be changed by a dedicated patch everywhere.
>
> pg_variable_is_visible seems to have done twice the system cache call.
> maybe follow through with the pg_table_is_visible, pg_type_is_visible
> code pattern.
>
>
done
>
> IN src/bin/psql/describe.c
> + appendPQExpBufferStr(&buf, "\nWHERE true\n");
> this is not needed?
>
Yes, it is a little bit messy, but it is necessary due to the usage of a
ValidateSQLNamePattern - it uses the "AND" operator, and
then there should be some expression before. I think that in this way, the
code is most simple. For objects based on
pg_class table is common usage "\nWHERE prokind = \"x\"\n" with the next
enhancement of filtering. But for variables
There is nothing like filtering inside the table pg_variable, so "WHERE
true\n" is the best analogy. See listConversions()
------------------------------------------------
> some of the `foreach` can change to foreach_oid, foreach_node
> see:
> https://git.postgresql.org/cgit/postgresql.git/commit/?id=14dd0f27d7cd56ffae9ecdbe324965073d01a9ff
done
>
> ------------------------------------------------
> doc/src/sgml/ref/create_variable.sgml
> <programlisting>
> CREATE VARIABLE var1 AS date;
> LET var1 = current_date;
> SELECT var1;
> </programlisting>
>
> v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch
> alone cannot do `LET var1 = current_date;`, `SELECT var1;`
> maybe the following patch can do it. but that makes
> we cannot commit
> v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch
> alone.
>
moved.
The patches 01 and 02 should be committed together to carry some valuable
functionality.
> ------------------------------------------------
> since CREATE VARIABLE is an extension to standard, so in create_schema.sgml
> Compatibility section,
> do we need to mention CREATE SCHEMA CREATE VARIABLE is an extension
> from standard
> ?
>
done
> -----------------------------------------------
>
> /*
> * Drop variable by OID, and register the needed session variable
> * cleanup.
> */
> void
> DropVariableById(Oid varid)
> i am not sure of the meaning of "register the needed session variable
> cleanup".
>
Without context it is messy. It is related to functionality introduced in
patch [PATCH 05/21] memory cleaning after DROP VARIABLE
So I moved text ", and register the needed session variable
* cleanup." there
Thank you very much for review
updated patchset attached
Regards
Pavel