[HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Kedar Potdar
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);

Re: [HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Greg Stark
On Fri, Mar 6, 2009 at 10:03 AM, Kedar Potdar kedar.pot...@gmail.com wrote: 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

Re: [HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Kedar Potdar
Thanks Greg, for showing interest. The problem here is I need to store values of different types into bytearray column of relation. On Fri, Mar 6, 2009 at 4:33 PM, Greg Stark st...@enterprisedb.com wrote: On Fri, Mar 6, 2009 at 10:03 AM, Kedar Potdar kedar.pot...@gmail.com wrote: The

Re: [HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Greg Stark
On Fri, Mar 6, 2009 at 11:41 AM, Kedar Potdar kedar.pot...@gmail.com wrote: Thanks Greg, for showing interest. The problem here is I need to store values of different types into bytearray column of relation. Oh, hm. I think you need to look at typlen instead of typbyval. But you have an

Re: [HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Greg Stark
On Fri, Mar 6, 2009 at 12:01 PM, Greg Stark st...@enterprisedb.com wrote: But you have an additional problem for typbyval types: the pointer to Datum isn't necessarily pointing at the right bytes. I think you have to use the GET_[1248]_BYTES macros depending on typlen. There may be a helper

Re: [HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Tom Lane
Kedar Potdar kedar.pot...@gmail.com writes: The problem here is I need to store values of different types into bytearray column of relation. Perhaps you should study the ANALYZE code. AFAICS your requirements are not different from those of the pg_statistic data store. You should do things

Re: [HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Kedar Potdar
Thanks Tom for your interest. I could find a workaround for the issue wherein the value of type which is not stored by value and has fixed data length, is being stored in string format to the relation. While retrieving from relation, this value is converted by using coerce_to_specific_type() to

Re: [HACKERS] Writing values to relation using bytearray ...

2009-03-06 Thread Tom Lane
Kedar Potdar kedar.pot...@gmail.com writes: I could find a workaround for the issue wherein the value of type which is not stored by value and has fixed data length, is being stored in string format to the relation. The answer is simple: don't do that. You do not need to, and should not,