What is the correct way to get the content of a varchar field in pgsql's source code

From: Felix(dot)徐 <ygnhzeus(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: What is the correct way to get the content of a varchar field in pgsql's source code
Date: 2014-01-20 08:54:41
Message-ID: CAPmhLM1th8j9Pve9GwwnD4WP-CcR9ymgoyNSRB8w7rf1RMSE3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,
I've learnt from the source code to open a table and scan it, like this:

Relation qma = try_relation_open(qmappersta, AccessShareLock);
if(qma!=NULL){
HeapScanDesc scan= heap_beginscan(qma,SnapshotNow,0,NULL);
HeapTuple tup;
TupleDesc tupDesc= RelationGetDescr(qma);
Datum *values;
bool *nulls;
int value1;
char value2;
while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL){
heap_deform_tuple(tup,tupDesc,values, nulls);
/* int values can be retrieved easily */
value1=values[0];
/* how to retrieve the content of a varchar field here? */
/* What I've tried: */
value2=VARDATA_ANY(values[2]);
/* But value2 seems to be incorrect
if the original data is "abcd", then I will get "abcd2" here(in
most cases, a "2" is appended to the data...), I'm wondering how to get
the data properly...
I've also tried VARDATA macro and encountered with the same
problem.
*/
}
}

Thanks!

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2014-01-20 09:05:41 Re: using rpmbuild with PostgreSQL 9.2.6 source code
Previous Message Devrim GÜNDÜZ 2014-01-20 08:52:33 Re: using rpmbuild with PostgreSQL 9.2.6 source code