X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3A52753239 for ; Fri, 8 Apr 2005 02:02:20 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72136-06 for ; Fri, 8 Apr 2005 01:02:10 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id F0B2852AA6 for ; Fri, 8 Apr 2005 02:02:09 +0100 (BST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id B975930952; Fri, 8 Apr 2005 03:01:46 +0200 (MET DST) From: ljb X-Newsgroups: pgsql.interfaces Subject: Re: What is the binary format for timestamps? Date: Fri, 8 Apr 2005 01:02:07 +0000 (UTC) Organization: Hub.Org Networking Services Lines: 18 Message-ID: References: <4255A00F.1010409@innovision.com> X-Complaints-To: usenet@news.hub.org User-Agent: slrn/0.9.8.1 (Linux) To: pgsql-interfaces@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.516 tagged_above=0 required=5 tests=FROM_ENDS_IN_NUMS X-Spam-Level: X-Archive-Number: 200504/24 X-Sequence-Number: 5440 marvin.bellamy@innovision.com wrote: > I'm trying to read/write timestamps as binary data, but I'm getting > garbage. It looks like there are 8 bytes of timestamp data (if I read > the headers correctly), which I had assumed was the time in millis from > the PostgreSQL epoch, but my values are way off. I wrote what I thought > was valid data to my timestamp columns, but my queries in the psql > console show (epoch?) for each one. When I read the binary content > back, I'd expect to get 0s, but I get some non-zero values. Don't use binary formats. But if you do: A date is returned as a 4-byte big-endian integer representing the number of days since POSTGRES_EPOCH_DATE. A timestamp is returned as an 8-byte big-endian double precision number of seconds since POSTGRES_EPOCH_DATE. A time is returned as an 8-byte big-endian double precision number of seconds since midnight. POSTGRES_EPOCH_DATE is January 1, 2000 (2000-01-01).