Writing values to relation using bytearray ... - Mailing list pgsql-hackers
From | Kedar Potdar |
---|---|
Subject | Writing values to relation using bytearray ... |
Date | |
Msg-id | bd8134a40903060203s31a7ac60i3e6bd77435e28e0f@mail.gmail.com Whole thread Raw |
Responses |
Re: Writing values to relation using bytearray ...
|
List | pgsql-hackers |
Hi,<br /><br /><div style="text-align: left;">I am trying to write values of different types to relation using followingcode.<br /></div><br /><span style="font-family: courier new,monospace;"> if(typbyval)</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> {</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> min_ba = (bytea*) palloc(len+1+VARHDRSZ);</span><br style="font-family: courier new,monospace;" /><span style="font-family: couriernew,monospace;"> memcpy(VARDATA(min_ba), &min_datum, len);</span><br style="font-family: couriernew,monospace;" /><span style="font-family: courier new,monospace;"> SET_VARSIZE(min_ba, len+VARHDRSZ);</span><brstyle="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;"> VARDATA(min_ba)[len] = '\0';</span><br style="font-family: courier new,monospace;" /><spanstyle="font-family: courier new,monospace;"> values[Anum_pg_partition_minval -1]= (Datum)min_ba;</span><br style="font-family: courier new,monospace;" /><br style="font-family: courier new,monospace;" /><spanstyle="font-family: courier new,monospace;"> max_ba = (bytea *) palloc(len+1+VARHDRSZ);</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> memcpy(VARDATA(max_ba),&max_datum, len);</span><br style="font-family: courier new,monospace;" /><span style="font-family:courier new,monospace;"> SET_VARSIZE(max_ba, len+VARHDRSZ);</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> VARDATA(max_ba)[len]= '\0';</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;"> values[Anum_pg_partition_maxval -1]=(Datum)max_ba;</span><br style="font-family: couriernew,monospace;" /><span style="font-family: courier new,monospace;"> }</span><br style="font-family: couriernew,monospace;" /><span style="font-family: courier new,monospace;"> else</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> {</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> values[Anum_pg_partition_minval -1]=min_datum;</span><br style="font-family: courier new,monospace;" /><span style="font-family:courier new,monospace;"> values[Anum_pg_partition_maxval -1]=max_datum;</span><brstyle="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;"> }</span><br /><br />These values are then written to relation using heap_form_tuple() and simple_heap_insert()functions. <br /><br />I am using following code to read the values from relation.<br /><br /><span style="font-family:courier new,monospace;"> part_attr = heap_getattr (pg_parttup,Anum_pg_partition_maxval,</span><brstyle="font-family: courier new,monospace;" /><span style="font-family: couriernew,monospace;"> pg_partrel->rd_att,&isnull);</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> if ( typbyval )</span><brstyle="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;"> {</span><brstyle="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;"> short_datum= 0;</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;"> memcpy(&short_datum, VARDATA_ANY(part_attr), len);</span><br style="font-family: courier new,monospace;"/><span style="font-family: courier new,monospace;"> part_attr = short_datum;</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> }</span><br style="font-family:courier new,monospace;" /><span style="font-family: courier new,monospace;"> else if (len != -1)</span><br style="font-family: courier new,monospace;" /><span style="font-family: courier new,monospace;"> part_attr = (Datum)VARDATA_ANY(part_attr);</span><br /><br /><br />The aforementioned code worksfine 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.<br/><br />Am i missing something here? <br /><br />Thanking you in anticipation.<br /><br />With warm regards,<br/>--<br />Kedar.<br />
pgsql-hackers by date: