Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tJkKI-004vAp-L0 for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Dec 2024 02:13:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tJkKD-00Eihl-TY for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Dec 2024 02:13:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tJkKD-00Eiha-Hc for pgsql-hackers@lists.postgresql.org; Sat, 07 Dec 2024 02:13:42 +0000 Received: from mail-vk1-xa2e.google.com ([2607:f8b0:4864:20::a2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tJkKB-001Rfn-1b for pgsql-hackers@lists.postgresql.org; Sat, 07 Dec 2024 02:13:41 +0000 Received: by mail-vk1-xa2e.google.com with SMTP id 71dfb90a1353d-515fbe0001aso524426e0c.2 for ; Fri, 06 Dec 2024 18:13:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733537617; x=1734142417; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yCLCxMAgeLVHE71/TFYSECMIGrFNtSRqaMMMt2vj4uo=; b=I4FlzBhrJ0MZ25cHJInYtRQ1IAIfNU1WzUICON4pIwIfCeBjAe9WHcAwpyNQycea95 Cjd+DeSWgshVfC//OqDHBpwrRA5VkulWWTXmmc2CAOegstyhRWV/e+33iYu3LURkECg8 aT4G03OGmbbhkRnTV5TgkSmGDZj+4WikMggzD2wMPmdrejnkS/AG2CkgoohIFZXW+Xiy EtoktclXn4IOApqhRdPEb+IZVppyM5LZsSsRqQAagiAKvscFD5FGmiQO/QQYS9EweTAn K8LDA05CTUBOWhfkQ1KYzq5sucXGQi5R5ezRFPY55+lFmyPo7aNvxZU5cJbxgIr1b40i GXLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733537617; x=1734142417; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yCLCxMAgeLVHE71/TFYSECMIGrFNtSRqaMMMt2vj4uo=; b=bPXvqh0ODr/eLE7Jonhj3vFxoHPmbPQZsQwgQICjlfxgavVLeDNfnt9YCd5Shxc1gk W8ZfMkHVZF2EP+ETWy+TQe8lEl8qPBlwNxEvLd1gtMRdr0oyCgs0qIncYExMniPtqvAX W8KOKkLmQmewQo8/twSN+CEK4oS1AOpLrBS9c8GS2tPpu+n3htz7qSjJOCpqVvcTrCx4 fe4hbRamnqYoVBderYhxzrGulGzCXhLOyjVhlfXquH7FnRUi5j0fSQNCANUUJ1mpQWB/ C3LXfV2goTC/4oM45gVCNGEpCxRuwWxdFRJG09gnfeKlgOhR7M4EH6aOK6NH7dCXsaMD 7vBA== X-Forwarded-Encrypted: i=1; AJvYcCVsOpRWRLdCtj+LGEb17keDVm0HlwqPqfXWKKybX0lXxcFhE7M2ruK1MPOpEeHbuCBOoDOfyVLGtFWjYWL8@lists.postgresql.org X-Gm-Message-State: AOJu0YwtSKjWoZaVjiYOG9e99BwnelcdDcG8Im6acEy9tTq3ZoK9i7W+ DhV/pjoZEYHlxusbywV/6tYlbZ16xKdOXr2hzXVIlLscjStRu5z0e9rEN5tKKAl79pn1Cef/WXW 4vy9RO4GnJ2m3nmwayHnEJzD7cYw= X-Gm-Gg: ASbGnct4KUFLPsQn2auQnlK+cpWYBB5MSaXMnxgTSfy1e7r5Lc2GML4ddevos37SXtO 5F02An5YAKS5AVH6Gc1E1HASiWGGUBi9O X-Google-Smtp-Source: AGHT+IF71YuO9SC5G4j1SrvtsC199oT/kzNUT3/WPjErQywkdqCIVXocWoMZjfMiZkUuhCkqrPIXwVabJJdta7+xNJA= X-Received: by 2002:a05:6122:3b8d:b0:50d:53ab:3d0c with SMTP id 71dfb90a1353d-515fc9e2af4mr6715184e0c.2.1733537617366; Fri, 06 Dec 2024 18:13:37 -0800 (PST) MIME-Version: 1.0 References: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> In-Reply-To: From: jian he Date: Sat, 7 Dec 2024 10:13:26 +0800 Message-ID: Subject: Re: proposal: schema variables To: Pavel Stehule Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Laurenz Albe , Erik Rijkers , Michael Paquier , Amit Kapila , DUVAL REMI , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Dec 5, 2024 at 2:52=E2=80=AFPM Pavel Stehule 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 =3D gettext_noop("session variable \"%s\" already exists in schema \"%s\""); break; 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? GetCommandLogLevel also needs to deal with case T_CreateSessionVarStmt? there are no regress tests for the change we made in find_composite_type_dependencies? It looks like it will be reachable for sure. CreateVariable, print out error position: if (get_typtype(typid) =3D=3D 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) =3D=3D 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)) 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. IN src/bin/psql/describe.c + appendPQExpBufferStr(&buf, "\nWHERE true\n"); this is not needed? ------------------------------------------------ some of the `foreach` can change to foreach_oid, foreach_node see: https://git.postgresql.org/cgit/postgresql.git/commit/?id=3D14dd0f27d7= cd56ffae9ecdbe324965073d01a9ff ------------------------------------------------ doc/src/sgml/ref/create_variable.sgml CREATE VARIABLE var1 AS date; LET var1 =3D current_date; SELECT var1; v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch alone cannot do `LET var1 =3D 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. ------------------------------------------------ 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 ? ----------------------------------------------- /* * 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 clean= up".