Unix Technical Forum

how can i get the binary format of timestamp?

This is a discussion on how can i get the binary format of timestamp? within the pgsql Hackers forums, part of the PostgreSQL category; --> Hello: I find that the real timestamp format(got from the file which is produced by copying binary to ) ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-12-2008, 03:03 AM
energumen@buaa.edu.cn
 
Posts: n/a
Default how can i get the binary format of timestamp?

Hello:
I find that the real timestamp format(got from the file which is produced by copying binary to ) is different from what i find in timestamp_send func.

i do think that the binary format of a timestamp "2006-04-18 11:20:20" should be "44 2B B0 6A 00 00 00 00" standing for "secs:1143713898, usecs:0" but in fact it is:"41A7 7DBA D400 0000 "

timestamp is defined as int64 or float8, when it is defined as int64, it looks like timeval, first 32 bits for seconds,second 32 bits for usec.
and from the timestamp_send func, it just changes the first 32 bits to binary then combines the next 32 bits

/* codes from timestamp_send
*/

Datum
timestamp_send(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
StringInfoData buf;

pq_begintypsend(&buf);
#ifdef HAVE_INT64_TIMESTAMP
pq_sendint64(&buf, timestamp);
#else
pq_sendfloat8(&buf, timestamp);
#endif
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}

/* codes from pq_sendint64
*/
void
pq_sendint64(StringInfo buf, int64 i)
{
uint32 n32;

/* High order half first, since we're doing MSB-first */
#ifdef INT64_IS_BUSTED
/* don't try a right shift of 32 on a 32-bit word */
n32 = (i < 0) ? -1 : 0;
#else
n32 = (uint32) (i >> 32);
#endif
n32 = htonl(n32);
appendBinaryStringInfo(buf, (char *) &n32, 4);

/* Now the low order half */
n32 = (uint32) i;
n32 = htonl(n32);
appendBinaryStringInfo(buf, (char *) &n32, 4);
}


so i do think that the binary format of a timestamp "2006-04-18 11:20:20" should be "44 2B B0 6A 00 00 00 00" standing for "secs:1143713898, usecs:0"

but in fact it is:" 41A7 7DBA D400 0000 " , i don't know why.

maybe, i have looked into a wrong func, then which is the right one?


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2008, 03:03 AM
Tom Lane
 
Posts: n/a
Default Re: how can i get the binary format of timestamp?

"energumen@buaa.edu.cn" <energumen@buaa.edu.cn> writes:
> timestamp is defined as int64 or float8, when it is defined as int64, it looks like timeval, first 32 bits for seconds,second 32 bits for usec.


No, it's seconds times 1000000, not times 2^32.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com