Creating HeapTuple from char and date values

From: Amin <amin(dot)fallahi(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Creating HeapTuple from char and date values
Date: 2022-12-07 02:06:31
Message-ID: CAF-KA8_RV9gbbRaqpZGAUSpdc=10Pb9URRdR4DiqtK-pOY=LdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

I am trying to create HeapTuple data structure.
First, I create a tuple descriptor:
TupleDesc *td=CreateTemplateTupleDesc(colCount);
Then, for each variable, I do:
TupleDescInitEntry(*td,v->varattno,NULL,v->vartype,v->vartypmod,0);
Then, I assign values:
if int32: values[v->varattno-1]=Int8GetDatum(myValue);
Similarly for float.
Finally, I create the HeapTuple:
HeapTuple tuple=heap_form_tuple(td,values,isnull);

Everything works fine with int and float. But I don't know how to handle
chars.
Let's say we have a character(10) column. One problem is v->vartypmod will
be set to 14. Shouldn't it be 10?
Second, how should I assign values? Is
values[v->varattno-1]=CStringGetDatum(myValue); correct? Should I set the
last parameter to TupleDescInitEntry? Why am I getting "invalid memory
alloc request size" or segfault with different configurations?

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2022-12-07 02:44:32 Re: Force streaming every change in logical decoding
Previous Message Masahiko Sawada 2022-12-07 02:00:58 Re: Force streaming every change in logical decoding