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

From Felix.徐
Subject What is the correct way to get the content of a varchar field in pgsql's source code
Date
Msg-id CAPmhLM1th8j9Pve9GwwnD4WP-CcR9ymgoyNSRB8w7rf1RMSE3A@mail.gmail.com
Whole thread Raw
List 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!

pgsql-general by date:

Previous
From: Devrim GÜNDÜZ
Date:
Subject: Re: [HACKERS] using rpmbuild with PostgreSQL 9.2.6 source code
Next
From: Craig Ringer
Date:
Subject: Re: using rpmbuild with PostgreSQL 9.2.6 source code