pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedQuestion about how to handle numeric (decimal) data types while using libpq
4+ messages / 3 participants
[nested] [flat]
* Question about how to handle numeric (decimal) data types while using libpq
@ 2021-07-06 11:04 Sudheer H R <sudheer.hr@tekenlight.com>
0 siblings, 2 replies; 4+ messages in thread
From: Sudheer H R @ 2021-07-06 11:04 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hello,
I am trying to use libpq for interfacing with PostgreSQL from a C/C++ based application.
I have tried to use binary format of data for both sending and receiving data to and from server (resultFormat = 1).
As I understand most binary types, int, float etc… are encoded in bing-endian byte order and they can be converted to appropriate host specific memory representations.
However NUMERIC datatype is a more complex structure with multiple ints and pointers.
I would like to know if there are published library functions that convert (to and from) NUMERIC field to say, long double datatype
Any pointers in this regard is appreciated.
Regards,
Sudheer
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Question about how to handle numeric (decimal) data types while using libpq
@ 2021-07-06 11:48 Dmitry Igrishin <dmitigr@gmail.com>
parent: Sudheer H R <sudheer.hr@tekenlight.com>
1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Igrishin @ 2021-07-06 11:48 UTC (permalink / raw)
To: Sudheer H R <sudheer.hr@tekenlight.com>; +Cc: pgsql-general@lists.postgresql.org
On Tue, Jul 6, 2021, 14:04 Sudheer H R <sudheer.hr@tekenlight.com> wrote:
> Hello,
>
> I am trying to use libpq for interfacing with PostgreSQL from a C/C++
> based application.
>
> I have tried to use binary format of data for both sending and receiving
> data to and from server (resultFormat = 1).
>
> As I understand most binary types, int, float etc… are encoded in
> bing-endian byte order and they can be converted to appropriate host
> specific memory representations.
>
> However NUMERIC datatype is a more complex structure with multiple ints
> and pointers.
>
> I would like to know if there are published library functions that convert
> (to and from) NUMERIC field to say, long double datatype
>
>
> Any pointers in this regard is appreciated.
>
Why not just use text format for NUMERIC?
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Question about how to handle numeric (decimal) data types while using libpq
@ 2021-07-06 12:02 Sudheer H R <sudheer.hr@tekenlight.com>
parent: Dmitry Igrishin <dmitigr@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Sudheer H R @ 2021-07-06 12:02 UTC (permalink / raw)
To: Dmitry Igrishin <dmitigr@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
It is not possible to use binary for some fields and text for some fields.
If text format has to be used, it will be applicable for all fields.
And this method involved converting to string format (sprint) on the server side and binary format from string (equivalent of sscanf), which is costly.
> On 06-Jul-2021, at 5:18 PM, Dmitry Igrishin <dmitigr@gmail.com> wrote:
>
>
>
> On Tue, Jul 6, 2021, 14:04 Sudheer H R <sudheer.hr@tekenlight.com <mailto:sudheer.hr@tekenlight.com>> wrote:
> Hello,
>
> I am trying to use libpq for interfacing with PostgreSQL from a C/C++ based application.
>
> I have tried to use binary format of data for both sending and receiving data to and from server (resultFormat = 1).
>
> As I understand most binary types, int, float etc… are encoded in bing-endian byte order and they can be converted to appropriate host specific memory representations.
>
> However NUMERIC datatype is a more complex structure with multiple ints and pointers.
>
> I would like to know if there are published library functions that convert (to and from) NUMERIC field to say, long double datatype
>
>
> Any pointers in this regard is appreciated.
> Why not just use text format for NUMERIC?
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Question about how to handle numeric (decimal) data types while using libpq
@ 2021-07-06 12:29 Peter Eisentraut <peter.eisentraut@enterprisedb.com>
parent: Sudheer H R <sudheer.hr@tekenlight.com>
1 sibling, 0 replies; 4+ messages in thread
From: Peter Eisentraut @ 2021-07-06 12:29 UTC (permalink / raw)
To: Sudheer H R <sudheer.hr@tekenlight.com>; pgsql-general@lists.postgresql.org
On 06.07.21 13:04, Sudheer H R wrote:
> I am trying to use libpq for interfacing with PostgreSQL from a C/C++ based application.
>
> I have tried to use binary format of data for both sending and receiving data to and from server (resultFormat = 1).
>
> As I understand most binary types, int, float etc… are encoded in bing-endian byte order and they can be converted to appropriate host specific memory representations.
>
> However NUMERIC datatype is a more complex structure with multiple ints and pointers.
>
> I would like to know if there are published library functions that convert (to and from) NUMERIC field to say, long double datatype
There is a third-party library called libpqtypes out there that adds
support for handling specific types on the libpq side. But I'm not sure
how up to date it is.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-07-06 12:29 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 11:04 Question about how to handle numeric (decimal) data types while using libpq Sudheer H R <sudheer.hr@tekenlight.com>
2021-07-06 11:48 ` Dmitry Igrishin <dmitigr@gmail.com>
2021-07-06 12:02 ` Sudheer H R <sudheer.hr@tekenlight.com>
2021-07-06 12:29 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox