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 1tRZy4-00ASKs-9N for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Dec 2024 16:47:12 +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 1tRZy2-001AL0-O6 for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Dec 2024 16:47:10 +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 1tRZy2-001AKs-Bv for pgsql-hackers@lists.postgresql.org; Sat, 28 Dec 2024 16:47:10 +0000 Received: from mail-vk1-xa2a.google.com ([2607:f8b0:4864:20::a2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tRZxz-002408-Dp for pgsql-hackers@lists.postgresql.org; Sat, 28 Dec 2024 16:47:09 +0000 Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-51bc2363fd7so879310e0c.2 for ; Sat, 28 Dec 2024 08:47:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735404426; x=1736009226; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=r/xZiUlMBT61hh0wxFrnVnVVqgk+pgUdCFpho2PuX2A=; b=ElAXqQ2azVS6F+hdLFBHCoQwxeqEMIy9amlSHWUlJebZ15o9TVqmt4HCCq5MMbAEJC f7gFWRQXH9YFXgdw68NZwig0zuH4wnUXitKwFUFB/RKdKYvECspUSLVqRSPeYHI8nNSG I28xgbD03ltY7ipl9gqRLrZlbWC9ihS7oFRpS64ed80jc19GY7oJOWxPbte3XUQD4ClX z1AyVbKUHAl4fFQNTbjy7K/L+pzMDzemlMvjsvJ6FkgPR8P9uc5vK8vVxzQzxOHvstPw 7hGE7M4iSDsEge91pL1nUKkuLN+yZX/FwhubyWsZb6A7EMmqjDh7twcEyTan674ZfAOl p76w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735404426; x=1736009226; h=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=r/xZiUlMBT61hh0wxFrnVnVVqgk+pgUdCFpho2PuX2A=; b=YVIsmivifF4aEuoY28j0oWC/e6EHYMbsPPAfyirVJj5BrSjwQk6LocBgQboBb+S5jO Wl4Pg8TLkrhVZ5s6a082Uq9Sh+o/PtpGJ/7QOE3CWDfLi2c8+B+Gnn+F9fGuzWsdWRM6 VDu+Ten1mNnL+fmiPlSl3EuW4P/loHGGn0kxqiSSb26dW942WBP9F81k82Mz4ZcJKn/I to1SxXEzCQXeOx5zmxjJPt1xj0ipRPfWCijiu6S7bAcgX3DenP03E0kdvfaaxgwPQIop lhXt7To4BtR5FlubI7aItFi+yBt7sZXh4lRa3xL+BHxT7+TfSg7E+Ee5xcbmAGJEqUw3 6SOA== X-Forwarded-Encrypted: i=1; AJvYcCXMdvRU8NuGsHnSVcPvQs/WoxN6yJo4FnBVRoNkjuQxXsbFmtEvGlkeyBhnjKudooczg4AQpjJodsfIj6Ey@lists.postgresql.org X-Gm-Message-State: AOJu0Yy1us73FMojl0WrW6F6YTvne2AdLHjqNu05szI30BGuvvFEeVIp hMsz3IGlT6my73maViOJFxK+S3VXfOI+77i/kQfDlDKiTefUw7P7+4FbK402vYfFEhDwF6v1Ukb PsNCUOoQ4rng1MFiDL/nX64AAPBw= X-Gm-Gg: ASbGncv7me75rbA1NQl/5c1wV1EwFZZrsVR/ZVGoQxRGuwgL9DenU7Hc5JNIw9VCKdB VsV7aKcj4KYmnxg8bvTUDTB0CA82git7xzG84T5w= X-Google-Smtp-Source: AGHT+IHYPBgJYVkokPPF8e8UU1Aq7LW0nqsNLjQK4UCgiLKSYzmPIiV2U+VHeOZA7ZUjZIvJf5HFFIL9jz5SpOO2O94= X-Received: by 2002:a05:6122:2398:b0:518:778b:70a1 with SMTP id 71dfb90a1353d-51b75d58cd3mr20608717e0c.7.1735404424181; Sat, 28 Dec 2024 08:47:04 -0800 (PST) MIME-Version: 1.0 References: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> <20241120201313.t4wbhld4ktgielaf@erthalion.local> In-Reply-To: From: jian he Date: Sun, 29 Dec 2024 00:46:28 +0800 Message-ID: Subject: Re: 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" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk hi. + if (stmt->collClause) + collation = LookupCollation(pstate, + stmt->collClause->collname, + stmt->collClause->location); + else + collation = typcollation;; two semi-colon. should be only one. ------------------<<>>>--------------- + /* locks the variable with an AccessShareLock */ + varid = IdentifyVariable(names, &attrname, ¬_unique, false); + if (not_unique) + ereport(ERROR, + (errcode(ERRCODE_AMBIGUOUS_PARAMETER), + errmsg("target \"%s\" of LET command is ambiguous", + NameListToString(names)), + parser_errposition(pstate, stmt->location))); the following are tests for the above "LET command is ambiguous" error message. create schema test; CREATE TYPE test AS (test int); CREATE variable test.test as test; set search_path to test; let test.test = 1; ------------------<<>>>--------------- + else + { + /* the last field of list can be star too */ + Assert(IsA(field2, A_Star)); + + /* + * In this case, the field1 should be variable name. But + * direct unboxing of composite session variables is not + * supported now, and then we don't need to try lookup + * related variable. + * + * Unboxing is supported by syntax (var).* + */ + return InvalidOid; + } I don't fully understand the above comments, add `elog(INFO, "%s:%d called", __FILE__, __LINE__); ` within the ELSE branch. Then I found out the ELSE branch doesn't have coverage tests. ------------------<<>>>--------------- + /* + * a.b.c can mean catalog.schema.variable or + * schema.variable.field. .... + /* + * a.b can mean "schema"."variable" or "variable"."field". + * Check both variants, and returns InvalidOid with + * not_unique flag, when both interpretations are + * possible. + */ here, we use the word "field", but the function IdentifyVariable above comment, we use word "attribute", for consistency's sake, we should use "attribute" instead of "field" +/* ----- + * IdentifyVariable - try to find a variable from a list of identifiers + * + * Returns the OID of the variable found, or InvalidOid. + * + * "names" is a list of up to four identifiers; possible meanings are: + * - variable (searched on the search_path) + * - schema.variable + * - variable.attribute (searched on the search_path) + * - schema.variable.attribute + * - database.schema.variable + * - database.schema.variable.attribute ------------------<<>>>---------------