dbTalk Databases Forums  

Re: how to use native C datatypes with the libpq api?

comp.databases.postgresql comp.databases.postgresql


Discuss Re: how to use native C datatypes with the libpq api? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: how to use native C datatypes with the libpq api? - 11-07-2006 , 06:01 AM






Sascha Bohnenkamp <bohnenkamp (AT) mevisbreastcare (DOT) de> wrote:
Quote:
how to use native C datatypes with the libpq api?

I mean what are the native representation of timestamp, int, float etc.
(all 'primitive' datatypes of postgresql) for the C language?

I know that I may go through a string representation, but I fear I would
sacrifice too much performance converting from/to string.

Additionaly I know that the 'native' int4 is the network form of int4
(ie. hton(int))

What about all the other types?
I found some in the example ... but there must be some documentation
about it .. I found nothing!
I am afraid that the only documentation for this is the source code.

Also, look at timestamps:

During ./configuration, you can specify --enable-integer-datetimes or
not, and the binary representation of a timestamp will depend on this
setting.
True, you could run 'SHOW integer_datetimes' and make your code depend
on the output, but it seems like a lot of trouble.

I think that the overhead of converting the string representation to
the binary representation is dwarfed by other things, such as query
parsing and network transmission time.

Also, using the string representation you can be certain that your code
will work with every server, no matter what machine it runs on and how
it is configured.

Yours,
Laurenz Albe


Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: how to use native C datatypes with the libpq api? - 11-07-2006 , 10:04 AM






Laurenz Albe <invite (AT) spam (DOT) to.invalid> wrote:
Quote:
Sascha Bohnenkamp <bohnenkamp (AT) mevisbreastcare (DOT) de> wrote:
how to use native C datatypes with the libpq api?

I mean what are the native representation of timestamp, int, float etc.
(all 'primitive' datatypes of postgresql) for the C language?

I know that I may go through a string representation, but I fear I would
sacrifice too much performance converting from/to string.

Additionaly I know that the 'native' int4 is the network form of int4
(ie. hton(int))

What about all the other types?
I found some in the example ... but there must be some documentation
about it .. I found nothing!

I am afraid that the only documentation for this is the source code.

Also, look at timestamps:

During ./configuration, you can specify --enable-integer-datetimes or
not, and the binary representation of a timestamp will depend on this
setting.
True, you could run 'SHOW integer_datetimes' and make your code depend
on the output, but it seems like a lot of trouble.
Just for the heck of it, I looked up the binary representation of
timestamp for --enable-integer-datetimes, and it is an 8 byte integer
in big-endian order.
It contains milliseconds before or after 2000-01-01 00:00:00 AD.
LLONG_MAX or 9223372036854775807LL is +infinity,
LLONG_MAX - 1LL is 294277-01-09 04:00:54.775806 AD
(the maximum possible value),
-LLONG_MAX - 1LL is -infinity,
-211813488000000000LL is 4714-11-24 00:00:00 BC,
and values between -9223372036854775807LL and -211813488000000001LL are
not allowed.

So you see what you're up against :^)

Yours,
Laurenz Albe


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.