Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XZeni-0002lh-Hx for pgsql-interfaces@arkaria.postgresql.org; Thu, 02 Oct 2014 11:44:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XZeni-0002QP-0e for pgsql-interfaces@arkaria.postgresql.org; Thu, 02 Oct 2014 11:44:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XZenh-0002QI-1U for pgsql-interfaces@postgresql.org; Thu, 02 Oct 2014 11:44:01 +0000 Received: from mout.kundenserver.de ([212.227.17.10]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XZenZ-0000uM-CG for pgsql-interfaces@postgresql.org; Thu, 02 Oct 2014 11:43:59 +0000 Received: from thilo.site (x590c0fd8.dyn.telefonica.de [89.12.15.216]) by mrelayeu.kundenserver.de (node=mreue101) with ESMTP (Nemesis) id 0MY6Vs-1XmsBK3Obo-00UpmJ; Thu, 02 Oct 2014 13:43:51 +0200 From: Thilo =?ISO-8859-1?Q?Rie=DFner?= To: pgsql-interfaces@postgresql.org Subject: Re: libpq binary data Date: Thu, 02 Oct 2014 13:43:49 +0200 Message-ID: <1592919.kcsFzWfsGI@thilo.site> User-Agent: KMail/4.11.5 (Linux/3.11.10-21-desktop; KDE/4.11.5; x86_64; ; ) In-Reply-To: <3808965.tNLrlL6qTR@thilo.site> References: <3808965.tNLrlL6qTR@thilo.site> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V02:K0:KB3xejq44fY9Aw1+Cld+YlaoX8ZrXVsqHDYDBuz9ub/ VTm5Hha1oprpotdT5MEkCvmpPQRLKVazcalcIC8oyq+yO9yTSI X5hiRM7mUQbLD/Tc+4DKn3qIG6SBYQrm/HciA2QHkB6mBch3mE jwZxy9KXI7evpxSm4IfFRjp6MMWB0VluzvXixnNY+/6demUSCS 8FFlR35dqoZx55O1aALEC8ORlAwMxwlJHUrzaB18lkYgrQBrzS qxxFWl1uHASBVzLVStMhQeRVqATDxSw0AMrU6zFlS7AdDZ3VxJ CLBwwuk4zc+QSJze9DvVYjH0IuvAxtYEue6g1xcJAzfwqsbLxA 5UviJhBfCiyxxSj3HEaI= X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-interfaces Precedence: bulk Sender: pgsql-interfaces-owner@postgresql.org Hello again, after trying the PQftype function on the date row, I realized, that the type is 701 which is a double. Treating the pointer as a double solved my problem, now I get the right number of seconds. But it is still necessary to swap the byte order from network to host with the function "ntohll" as shown below. Hope this helps someone stucking in a similar problem. Thilo > Hello, > I try to get the epoch value of a date via the > PQexecParams(conn, "SELECT extract(epoch from date + time) as epoch, content > FROM daten .....); > In that database, the timestamp ist stored in the two fields date and time. > I want to get this data in binary form. The > PQfsize(res, 1); > tells me, that the size of the returned data is 8 byte (in contrast to the > standard size of epoch, which is meant to be 4 byte) > I don't manage to get the epoch valule (seconds since 1970) from that > returned value. After ntohll (which I wrote as a wrapper around ntohl for > long int, see below) it is a very huge value (4743709917079142400) but it > should be 1412179252 as I get it from the psql interface, when I type in > the same command. > What am I missing or doing wrong? > Thanks for any help in advance > > Thilo > > unsigned long int ntohll(long int x) > { > if (ntohl(1) == 1) > return x; > else > return (long int) (ntohl((int)((x << 32) >> 32))) << 32 | (long > int)ntohl(((int)(x >> 32))); > } -- Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-interfaces