how correctly detoast a Datum value?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: how correctly detoast a Datum value?
Date: 2010-11-19 19:25:44
Message-ID: AANLkTimb5uNhtL_-nOE-xFWOrceXgrGdF1sJ1OapsTKx@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2010-11-19 19:31:05 Re: UNNEST ... WITH ORDINALITY (AND POSSIBLY OTHER STUFF)
Previous Message David Fetter 2010-11-19 19:06:02 Re: UNNEST ... WITH ORDINALITY (AND POSSIBLY OTHER STUFF)