Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m0jmm-0000hO-Dh for pgsql-general@arkaria.postgresql.org; Tue, 06 Jul 2021 12:02:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m0jml-0005bK-2m for pgsql-general@arkaria.postgresql.org; Tue, 06 Jul 2021 12:02:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m0jmk-0005bC-PB for pgsql-general@lists.postgresql.org; Tue, 06 Jul 2021 12:02:42 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m0jmh-00067H-FB for pgsql-general@lists.postgresql.org; Tue, 06 Jul 2021 12:02:42 +0000 Received: by mail-pf1-x431.google.com with SMTP id 145so5273003pfv.0 for ; Tue, 06 Jul 2021 05:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tekenlight.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=JgDf9w18ciKKS/C0yOVS7PJ3DASxmtn6Ao0vcKgrPJs=; b=RKJGIIjDjd6DeHbRwNvdLDVQokxDezlg4q6fl5yEpQRI+msybpXjwi9ZN7WeLa8OWJ t1XwEtGdoYBwg7s+mXoq/jZW7lipNjDyzixoi2UKrlp23McR5AQgmKH/4yuLyM4h82IQ 1MoTFGx9XmYFwe/rAXqK/bSFzLsj8nFEMt6xIhLvgV5s6mnUKUDPsJKvhOYukwifyJEH 0hiw44tn97IjhORYn5vPvxBsx/DjZcMlHAK/uzreRLImZ+gNQHCvx7sWkySV5a5L1mgx 1T7+nsmYSXur4ujAzTYqmltR3MqYxCGX2f7KBrdKPGP+MI3kYMBHhMzILWqXK6HDdhFK ZjzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=JgDf9w18ciKKS/C0yOVS7PJ3DASxmtn6Ao0vcKgrPJs=; b=DaN6naoEMn0hxWQRK0oWLwjAbRag/7LipF2UTCevu+TJveA4H0FyY55WpftiOobIxa CU1Rqrc3Bz4oQiZMqFutANZSGDne30KHRcDaPtwOewg7J947kzHy3SfuOYHyjEsEmrXN dvAR3baye7YTZzCQBGmQRKHpJEfm4s/lVK5rHoVQ5fZTRXRjY07SEjhwjVhlus6DrzJi UDIQEOJpHLqMB2QG0g7sHn+jGh5wNo8xjv9OswSeeeEAbAywaBy5wOg6/iTa8oiiFQxX gZ2DKy9mv/AKzcV1ZL47hAjCH717ESpskA1NhWxsFmVjAvxP4t9Q9IpEXbxuJ+6Ysmzz SZkg== X-Gm-Message-State: AOAM530HmJE9WDpqZH5Jo4n0uc5d6LZmS2uvbMdRdUKApD8RoLJfdzEM Rm/KLPJDfUHoNQemwYafPQFc5w== X-Google-Smtp-Source: ABdhPJz9alexprrmD6yARagbNTxN/d0ZcapEnfOpdJ5BCGShlO1MnZf3dA6SuMO2qnk7T8uJODmHaw== X-Received: by 2002:a63:145d:: with SMTP id 29mr8910058pgu.135.1625572957073; Tue, 06 Jul 2021 05:02:37 -0700 (PDT) Received: from smtpclient.apple ([136.185.129.152]) by smtp.gmail.com with ESMTPSA id x24sm2610008pfu.209.2021.07.06.05.02.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jul 2021 05:02:36 -0700 (PDT) From: Sudheer H R Message-Id: <954FFB92-1BA7-400A-AC16-A9B18F1FCBEA@tekenlight.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_140BC77C-7469-4177-B173-1B3F5FEED897" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) Subject: Re: Question about how to handle numeric (decimal) data types while using libpq Date: Tue, 6 Jul 2021 17:32:33 +0530 In-Reply-To: Cc: pgsql-general@lists.postgresql.org To: Dmitry Igrishin References: <63A4A360-8A41-476B-A5B6-D00088D6F590@tekenlight.com> X-Mailer: Apple Mail (2.3654.100.0.2.22) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_140BC77C-7469-4177-B173-1B3F5FEED897 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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 wrote: >=20 >=20 >=20 > On Tue, Jul 6, 2021, 14:04 Sudheer H R > wrote: > Hello, >=20 > I am trying to use libpq for interfacing with PostgreSQL from a C/C++ = based application. >=20 > I have tried to use binary format of data for both sending and = receiving data to and from server (resultFormat =3D 1). >=20 > As I understand most binary types, int, float etc=E2=80=A6 are encoded = in bing-endian byte order and they can be converted to appropriate host = specific memory representations. >=20 > However NUMERIC datatype is a more complex structure with multiple = ints and pointers. >=20 > I would like to know if there are published library functions that = convert (to and from) NUMERIC field to say, long double datatype >=20 >=20 > Any pointers in this regard is appreciated. > Why not just use text format for NUMERIC? --Apple-Mail=_140BC77C-7469-4177-B173-1B3F5FEED897 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 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> 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 =3D 1).

As I understand most binary types, int, float etc=E2=80=A6 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?

= --Apple-Mail=_140BC77C-7469-4177-B173-1B3F5FEED897--