Thread: Convertion of date/time binary format to text format

Convertion of date/time binary format to text format

From
"Mavinakuli, Prasanna (STSD)"
Date:
Hi,

I am getting data in binary mode..(schema contains bytea so we need to
get result in binary format)

But we have timestamp in schema.this would be also in
Binary format.

So how can I get the ASCII format/Text format from that binary format.

Please get me the steps to convert timestamp column which is of
****binary mode to TEXT/ASCII mode****..


Thanking You,
Prasanna.


Re: Convertion of date/time binary format to text format

From
Volkan YAZICI
Date:
On Dec 23 12:25, Mavinakuli, Prasanna (STSD) wrote:
> So how can I get the ASCII format/Text format from that binary
> format.
>
> Please get me the steps to convert timestamp column which is of
> binary mode to TEXT/ASCII mode

I attached an example program which answers your question. Hope
this helps.

(I skipped byte order conversions in my example for simplicity. Don't
forget 'em in your own program for portability.)


Regards.

--
"We are the middle children of history, raised by television to believe
that someday we'll be millionaires and movie stars and rock stars, but
we won't. And we're just learning this fact," Tyler said. "So don't
fuck with us."

Attachment

Re: Convertion of date/time binary format to text format

From
Volkan YAZICI
Date:
On Jan 02 09:26, Mavinakuli, Prasanna (STSD) wrote:
> Could u give me one more favour..
> That is can u please elobarate on bytea order conversion...?

You can find lots of information about "byte order coersion" on the
internet. I'd suggest reading these links:
 http://www.cs.umass.edu/~verts/cs32/endian.html http://www.netrino.com/Publications/Glossary/Endianness.html

But for a "quick & dirty" answer:
o. You don't have to make any byte order coersion on types smaller   than 0xFF = 256 bytes - like char.
o. You _should_ make byte order coersion on types bigger than   256 bytes - like int. From PostgreSQL
documentation'slibpq-example.html:
char *iptr;int   ival;
   iptr = PQgetvalue(res, i, i_fnum);
   /*    * The binary representation of INT4 is in network byte order,    * which we'd better coerce to the local byte
order.   */   ival = ntohl(*((uint32_t *) iptr));   Otherwise, you'll encounter different results in data transfers
ondifferent architectures with different endianness.
 


Regards.