Writing values to relation using bytearray ...

From: Kedar Potdar <kedar(dot)potdar(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Writing values to relation using bytearray ...
Date: 2009-03-06 10:03:43
Message-ID: bd8134a40903060203s31a7ac60i3e6bd77435e28e0f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2009-03-06 10:25:13 Re: Updates of SE-PostgreSQL 8.4devel patches (r1668)
Previous Message ITAGAKI Takahiro 2009-03-06 08:03:56 Re: Additional DTrace Probes