From: Wilhansen Li <willi.t1@gmail.com>
To: pgsql-interfaces@postgresql.org
Subject: Re: Timestamp with libpq
Date: Mon, 13 Oct 2008 17:32:30 +0800
Message-ID: <bc9549a50810130232nf40bfd2l2aee3c8c3ff5ec7e@mail.gmail.com> (raw)
In-Reply-To: <1223884381.3502.10.camel@vie063.fabagl.fabasoft.com>
References: <1223884381.3502.10.camel@vie063.fabagl.fabasoft.com>
Actually, I've done this before. And, uh, you can check out my blog for
details:
http://blogs.crammerz-inc.net/thunk/2007/05/09/grabbing_time_in_postgresql_using_libpq
On Mon, Oct 13, 2008 at 3:53 PM, Jakob Lechner <jakob.lechner@applstrudl.com
> wrote:
> Hello everybody,
>
> I'm trying to convert timestamp values returned by an SQL query into an
> unix time_t. I'm using the libpq library.
>
> For executing the query I use "PQexecParams" with the parameter
> "resultFormat" set to 1 in order to obtain results in binary format.
>
> The table I'm fetching data from was created with the following
> statement:
> create table testtable (c timestamp);
>
> The statement executed by "PQexecParams" is a simple "select"-statement:
> select * from testtable;
>
>
> I've read that postgres internally handles timestamps as double numbers,
> where the timestamp is represented in seconds since 2000-01-01.
> Thus, I assumed the data returned by "PQgetvalue" for the timestamp
> field is encoded in this format. Then I wrote a little routine, which
> takes the double number obtained from "PQgetvalue" and converts it into
> an unix time_t. This works perfectly if the postgres server (version
> 8.1.4-1.1) runs on RHEL but if I query the data from a postgres server
> (version 8.1.4-1.3) runnning on SLES the result totally wrong.
>
> Any ideas?
>
> Best regards
> Jakob Lechner
>
>
> --
> Jakob Lechner
> Research & Development
> appl.strudl Software GmbH
> Honauerstraße 4
> A-4020 Linz
> Tel.: [+43] (70) 60 61 62
> Fax: [+43] (70) 60 61 62-609
> E-Mail: jakob.lechner@applstrudl.com
> Web: http://www.applstrudl.com
> Handelsgericht Linz, FN 303988 t
>
> --
> Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-interfaces
>
--
Life is too short for dial-up.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: willi.t1@gmail.com
Subject: Re: Timestamp with libpq
In-Reply-To: <bc9549a50810130232nf40bfd2l2aee3c8c3ff5ec7e@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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