Skip to content

Commit a03ec09

Browse files
author
anju15bharti
committed
fix: Use full ENR name for temp tables in ATParseTransformCmd
ATParseTransformCmd reconstructs the AlterTableStmt RangeVar from RelationGetRelationName(rel), which returns NameStr(rel->rd_rel->relname). The Name type is capped at NAMEDATALEN-1 (63 chars), so temp table names >= 64 chars get clipped. This causes subsequent RangeVarGetRelidExtended calls to fail because the clipped name doesn't match the full name stored in ENR. Fix: For T-SQL #temp tables, look up the full untruncated name from ENR using get_ENR_withoid and use it as the RangeVar relname instead. Signed-off-by: anju15bharti <abanju@amazon.com>
1 parent b3c9bac commit a03ec09

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/backend/commands/tablecmds.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5834,6 +5834,23 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
58345834
makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
58355835
pstrdup(RelationGetRelationName(rel)),
58365836
-1);
5837+
5838+
/*
5839+
* For T-SQL #temp tables with long names (>= NAMEDATALEN), the relation
5840+
* descriptor stores the name clipped to NAMEDATALEN-1 (63 chars) due to the
5841+
* Name type limitation. However, ENR stores the full untruncated name which
5842+
* is what subsequent lookups via RangeVarGetRelidExtended need to match.
5843+
* Replace the clipped relname with the full name from ENR.
5844+
*/
5845+
if (sql_dialect == SQL_DIALECT_TSQL &&
5846+
RelationGetRelationName(rel)[0] == '#')
5847+
{
5848+
EphemeralNamedRelation enr = get_ENR_withoid(currentQueryEnv,
5849+
RelationGetRelid(rel),
5850+
ENR_TSQL_TEMP, true);
5851+
if (enr)
5852+
atstmt->relation->relname = pstrdup(enr->md.name);
5853+
}
58375854
atstmt->relation->inh = recurse;
58385855
atstmt->cmds = list_make1(cmd);
58395856
atstmt->objtype = OBJECT_TABLE; /* needn't be picky here */

0 commit comments

Comments
 (0)