Обсуждение: how correctly detoast a Datum value?

Поиск
Список
Период
Сортировка

how correctly detoast a Datum value?

От
Pavel Stehule
Дата:
Hello

I try to explicitly detoast a plpgsql var, but I this code breaks a content.

what is wrong?
       switch (datum->dtype)       {               case PLPGSQL_DTYPE_VAR:                       {
        PLpgSQL_var *var = (PLpgSQL_var *) datum;
 
                               *typeid = var->datatype->typoid;                               *typetypmod =
var->datatype->atttypmod;                              *isnull = var->isnull;
 
                               /*.                                * explicitly detoasting a possible
toasted values,                                * should to protect us under repeated
detoasting.                                * and decomprimiting                                */
       if (!*isnull &&
 
!var->datatype->typbyval && var->datatype->typlen == -1)                               {
      struct varlena *datum =
 
PG_DETOAST_DATUM(var->value);
                                       if ((Pointer) datum !=
DatumGetPointer(var->value))                                       {
free_var(var);                                              var->value =
 
PointerGetDatum(datum);                                       }                                       *value =
var->value;                              }                               else
*value= var->value;
 
                               break;                       }

Regards

Pavel Stehule