From 8d9455b7fc1cb46c089ebf4f06ca3fecf64ea0f5 Mon Sep 17 00:00:00 2001 From: Sharu Goel <30777678+thephantomthief@users.noreply.github.com> Date: Wed, 2 Feb 2022 00:11:01 +0530 Subject: [PATCH] Ignore catalog (DB) name in multi-db handling logic for temp tables The schema name is set to NULL for temp tables because schema name is silently ignored in SQL server. But we didn't set the catalog (DB) name to NULL when one is provided. This causes a crash when we use the schema name in a string comparison. This commit addresses this issue by also setting the catalog (DB) name to NULL for temp tables Task: BABEL-2692 Author: Huansong Fu Signed-off-by: Sharu Goel --- src/backend/parser/gram.y | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index bdd24ae442b..833cde1da17 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -15108,10 +15108,11 @@ qualified_name: case 2: $$->catalogname = downcaseIfTsqlAndCaseInsensitive($1); $$->schemaname = downcaseIfTsqlAndCaseInsensitive(strVal(linitial($2))); - /* TSQL temp table names. Schema name is allowed but ignored for temp tables.*/ + /* TSQL temp table names. Catalog and schema names allowed but ignored for temp tables.*/ if (strncmp(strVal(lsecond($2)), "#", 1) == 0 || strncmp(strVal(lsecond($2)), "##", 2) == 0) { $$->relpersistence = RELPERSISTENCE_TEMP; + $$->catalogname = NULL; $$->schemaname = NULL; } $$->relname = downcaseIfTsqlAndCaseInsensitive(strVal(lsecond($2)));