mirror of https://github.com/citusdata/citus.git
Refactor process_entry_pair to improve clarity in handling NextValueExpr return type
parent
153901fc86
commit
30eb4a1cbe
|
@ -1699,43 +1699,32 @@ process_entry_pair(TargetEntry *insertEntry, TargetEntry *selectEntry,
|
||||||
Form_pg_attribute attr, int targetEntryIndex,
|
Form_pg_attribute attr, int targetEntryIndex,
|
||||||
List **projectedEntries, List **nonProjectedEntries)
|
List **projectedEntries, List **nonProjectedEntries)
|
||||||
{
|
{
|
||||||
Oid sourceType = exprType((Node *) selectEntry->expr);
|
Oid effectiveSourceType = exprType((Node *) selectEntry->expr);
|
||||||
Oid targetType = attr->atttypid;
|
Oid targetType = attr->atttypid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the select expression is a NextValueExpr, use its actual return type.
|
* If the select expression is a NextValueExpr, use its actual return type.
|
||||||
*
|
*
|
||||||
* NextValueExpr represents a call to the nextval() function, which is used to
|
* NextValueExpr represents a call to the nextval() function, which is used to
|
||||||
* obtain the next value from a sequence—commonly for populating auto-increment
|
* obtain the next value from a sequence—commonly for populating auto-increment
|
||||||
* columns. In many cases, nextval() returns an INT8 (bigint), but the actual
|
* columns. In many cases, nextval() returns an INT8 (bigint), but the actual
|
||||||
* return type may differ depending on database configuration or custom implementations.
|
* return type may differ depending on database configuration or custom implementations.
|
||||||
*
|
*
|
||||||
* Since the target column might have a different type (e.g., INT4), we need to
|
* Since the target column might have a different type (e.g., INT4), we need to
|
||||||
* obtain the real return type of nextval() to ensure that any type coercion is applied
|
* obtain the real return type of nextval() to ensure that any type coercion is applied
|
||||||
* correctly. This is done by calling GetNextvalReturnTypeCatalog(), which looks up the
|
* correctly. This is done by calling GetNextvalReturnTypeCatalog(), which looks up the
|
||||||
* function in the catalog and returns its return type. The effectiveCastFromType is then
|
* function in the catalog and returns its return type. The effectiveSourceType is then
|
||||||
* set to this value, ensuring that subsequent comparisons and casts use the correct type.
|
* set to this value, ensuring that subsequent comparisons and casts use the correct type.
|
||||||
*/
|
*/
|
||||||
if (IsA(selectEntry->expr, NextValueExpr))
|
if (IsA(selectEntry->expr, NextValueExpr))
|
||||||
{
|
{
|
||||||
Oid nextvalType = GetNextvalReturnTypeCatalog();
|
effectiveSourceType = GetNextvalReturnTypeCatalog();
|
||||||
if (targetType != nextvalType)
|
|
||||||
{
|
|
||||||
append_casted_entry(insertEntry, selectEntry,
|
|
||||||
nextvalType, targetType,
|
|
||||||
attr->attcollation, attr->atttypmod,
|
|
||||||
targetEntryIndex,
|
|
||||||
projectedEntries, nonProjectedEntries);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*projectedEntries = lappend(*projectedEntries, selectEntry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (sourceType != targetType)
|
|
||||||
|
if (effectiveSourceType != targetType)
|
||||||
{
|
{
|
||||||
append_casted_entry(insertEntry, selectEntry,
|
append_casted_entry(insertEntry, selectEntry,
|
||||||
sourceType, targetType,
|
effectiveSourceType, targetType,
|
||||||
attr->attcollation, attr->atttypmod,
|
attr->attcollation, attr->atttypmod,
|
||||||
targetEntryIndex,
|
targetEntryIndex,
|
||||||
projectedEntries, nonProjectedEntries);
|
projectedEntries, nonProjectedEntries);
|
||||||
|
|
Loading…
Reference in New Issue