Hi,

I am trying to write values of different types to relation using following
code.

            if(typbyval)
            {
                min_ba = (bytea *) palloc(len+1+VARHDRSZ);
                memcpy(VARDATA(min_ba), &min_datum, len);
                SET_VARSIZE(min_ba, len+VARHDRSZ);
                VARDATA(min_ba)[len] = '\0';
                values[Anum_pg_partition_minval        -1]= (Datum)min_ba ;

                max_ba = (bytea *) palloc(len+1+VARHDRSZ);
                memcpy(VARDATA(max_ba), &max_datum, len);
                SET_VARSIZE(max_ba, len+VARHDRSZ);
                VARDATA(max_ba)[len] = '\0';
                values[Anum_pg_partition_maxval        -1]=(Datum)max_ba;
            }
            else
            {
                values[Anum_pg_partition_minval        -1]=min_datum;
                values[Anum_pg_partition_maxval        -1]=max_datum;
            }

These values are then written to relation using heap_form_tuple() and
simple_heap_insert() functions.

I am using following code to read the values from relation.

        part_attr = heap_getattr (pg_parttup,Anum_pg_partition_maxval,
                                            pg_partrel->rd_att,&isnull);
        if ( typbyval )
        {
            short_datum = 0;
            memcpy(&short_datum, VARDATA_ANY(part_attr), len);
            part_attr = short_datum;
        }
        else if (len != -1 )
            part_attr = (Datum)VARDATA_ANY(part_attr);


The aforementioned code works fine for types like int, data, text and I can
read values from the relation correctly. The problem arises for type
"float8" which is not "by value" type and it has fixed length (8) where I
can't read the values written to relation correctly.

Am i missing something here?

Thanking you in anticipation.

With warm regards,
--
Kedar.

Reply via email to