how correctly detoast a Datum value? - Mailing list pgsql-hackers

From Pavel Stehule
Subject how correctly detoast a Datum value?
Date
Msg-id AANLkTimb5uNhtL_-nOE-xFWOrceXgrGdF1sJ1OapsTKx@mail.gmail.com
Whole thread Raw
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: UNNEST ... WITH ORDINALITY (AND POSSIBLY OTHER STUFF)
Next
From: Alvaro Herrera
Date:
Subject: Re: UNNEST ... WITH ORDINALITY (AND POSSIBLY OTHER STUFF)