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 1o7KHq-0004WN-1M for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 17:18:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7KHo-0003fD-3j for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 17:18:32 +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 1o7KHn-0003ez-MQ for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 17:18:31 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o7KHj-0000Pf-Ia for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 17:18:31 +0000 Received: by mail-pg1-x536.google.com with SMTP id r66so2970445pgr.2 for ; Fri, 01 Jul 2022 10:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lRPyhXHxvK3X9MQvI892rBwjX6Eog6uQR6nITZRKop4=; b=gxJLNB6rGLIdNgjjgWqm5ir5Autt0rBEKFsdhk5VOESoHJe5+99v1aFAAOJFdczBqk u0F71IyR/cWVq+ATIPVceSK7dSEFCqki5U7k/Gjl72XjCCAqQ4Ave8ft1YmnSebyRh7q nrsq9cfaNkvIxPez5IFnQ4h8E2pXZKzV1tPNvlGhcgB25c07HoyN4VDXH2gaPjckjuM+ x/RFk5AjNhxvxmWbLl5g4tOGUd65P3w/f8UavVZwyGI6Ab8iIb91XWStdG7p85oAVd3F RxBK/Zxl2E2IJwLfrv51xrUfxZM16BjUTUB7fiWE6Yzyg3lslDqfi2GRX2jgxcgRi30G AJJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=lRPyhXHxvK3X9MQvI892rBwjX6Eog6uQR6nITZRKop4=; b=AsksHmRI0Ebkna3+PcaC2g7Sb9Hlr8dix6EhFLbRTVgRyj6Nt1weEYUpFdTfm7bKk9 wEUYAhiGx7RQrC71iibaS7kI1175mpvKBBbr+CeCD+sD3Mbnr9ESVPAVZBl/u+oOL6Qy nKDDHos2MvzeqnqoONjwIHUI7GfHtEkP1n693i0wCHfREKa8uKmNV/JoXOkiY3XX69Xb HD4wNEGDAb879r7Znq8TaFyGGb92ClFpEfUE07VkjrDIUCVXcygUGmtHv/noKhtcnHwR 5eMkvXZ8mxYiVo3WXbIGDc8ngQfGg0XnOIrPlXPaf962prFBsRQklwG+in0s1eJ5g0y4 ABYA== X-Gm-Message-State: AJIora8APr4rEtqK/EtWlRilvIvCHPM47+SRq9wY5mkH+7tPg224ajZF wAPOmhUqYY9iUk8QDGrbfkU= X-Google-Smtp-Source: AGRyM1u21MWuOAsAvHZrhPL4JNTqRXF2dsCyQNugnYm0y3MVEoLJ7hMOtF+AptTkm1WYbYGWZ0dhag== X-Received: by 2002:a63:8ac2:0:b0:411:8061:c10f with SMTP id y185-20020a638ac2000000b004118061c10fmr12371970pgd.262.1656695905293; Fri, 01 Jul 2022 10:18:25 -0700 (PDT) Received: from workstation-mark-wong (97-120-16-21.ptld.qwest.net. [97.120.16.21]) by smtp.gmail.com with ESMTPSA id q18-20020a170902dad200b00161f9e72233sm8267416plx.261.2022.07.01.10.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 10:18:23 -0700 (PDT) Date: Fri, 1 Jul 2022 10:18:20 -0700 From: Mark Wong To: Tom Lane Cc: Robert Haas , Greg Stark , Chapman Flack , Ashutosh Bapat , PostgreSQL Hackers Subject: Re: real/float example for testlibpq3 Message-ID: References: <2511609.1646061540@sss.pgh.pa.us> <621D4CF3.6090808@anastigmatix.net> <2746817.1646088530@sss.pgh.pa.us> <967228.1655408510@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="r+VDod33A49rXvwb" Content-Disposition: inline In-Reply-To: <967228.1655408510@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --r+VDod33A49rXvwb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jun 16, 2022 at 03:41:50PM -0400, Tom Lane wrote: > Robert Haas writes: > > On Tue, Jun 14, 2022 at 1:40 PM Mark Wong wrote: > >> I've created a function for each data type with the idea that an example > >> for handling a specific data type can be more easily reviewed by looking > >> in a single place. > >> I've added examples for REAL, TIMESTAMP WITHOUT TIME ZONE, and BOOLEAN > >> to try to illustrate how testlibpq3.sql and testlibpq3.c will grow if > >> this is a good way to go. > > > I'm not sure that we want to let these test programs grow very large. > > In particular, I don't think we should let ourselves get sucked into > > adding an example for every data type under the sun -- if that's > > wanted, the solution is perhaps to add documentation for the binary > > formats, not hide impromptu documentation inside a test program. But > > doing this much seems OK to me. > > Yeah, "hiding impromptu documentation inside a test program" is what > this looks like, and I'm not sure that's a reasonable way to go. > > (1) Who's going to think to look in src/test/examples/testlibpq3.c for > documentation of binary formats? > > (2) The useful details are likely to get buried in notational and > portability concerns, as I think your build failure illustrates. > > (3) I bet few if any packagers install these files, so that the new > info would be unavailable to many people. > > I think some new appendix in the main SGML docs would be the appropriate > place if we want to provide real documentation. Just wanted to do another quick check in before I go too far. How do does this start look? Extending the libpq section with a code snippet and description per data type? Regards, Mark --r+VDod33A49rXvwb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="libpq-binary-format-doc-v0.patch" diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 37ec3cb4e5..44c60223ee 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -8874,6 +8874,109 @@ int PQisthreadsafe(); + + Binary Format + + Various libpq functions support sending or + receiving data in binary format. Data in binary format requires the + application to be handle any differences between the system and the network + byte order. + + + + demonstrates how to write a complete + program that uses libpq functions that request + data in binary foramt. This example shows how to handle only a few data + types. This section will detail the handling of as many of the data types + as possible. See for descriptions of each of the + built-in data types. + + + + <type>boolean</type> + + A boolean is transmitted as single byte that, when cast to + an int, will be 0 for + false and 1 for + true. + + + + + + + + <type>real</type> + + A real is composed of 4 bytes and needs to be handled + correctly for byte order. + + + + + + + + <type>timestamp without time zone</type> + + A timestamp without time zone is a 64-bit data type + representing the number of microseconds since January 1, 2000. It can be + converted into a broken-down time representation by converting the time + into seconds and saving the microseconds elsewhere. + + + Note that in C time is counted from January 1, 1970 so this discrepency + needs to be accounted for in addition to handling the network byte order. + + +tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, + tm->tm_min, tm->tm_sec, mantissa); +]]> + + + + Building <application>libpq</application> Programs --r+VDod33A49rXvwb--