From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Yan Cheng Cheok <yccheok(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Get Unix timestamp from SQL timestamp through libpq |
Date: | 2010-01-11 12:31:27 |
Message-ID: | b42b73151001110431x7fde99baqc929351e7db8a835@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Jan 11, 2010 at 1:16 AM, Yan Cheng Cheok <yccheok(at)yahoo(dot)com> wrote:
> I know I can convert SQL timestamp to unix timestamp, using the following way.
>
> SELECT extract(epoch FROM now());
>
> Now, I have a stored procedure function, which will directly return a table row to the caller. One of the row field is "timestamp" type.
>
> In my application, I am using libpq. I wish to use libpq functions (or any c/c++ function), to convert "2010-01-11 13:10:55.283" into unix timestamp. Off course, I can create another stored procedure named
>
> SQLTimestamp2UnixTimestamp
> SELECT extract(epoch FROM $1);
>
> But I just wish to accomplish this task with a single c/c++ function call, without involving stored procedure.
libpqtypes can do this (and it's much faster if you use libpqtypes to
issue the query).
PGtimestamptz ts;
res = PQexef("select now()");
PQgetf(res, 0, "%timestamptz", 0 , &ts);
int epoch = ts.epoch;
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Steve White | 2010-01-11 13:06:04 | Re: access computed field of RECORD variable |
Previous Message | tamanna madaan | 2010-01-11 11:59:54 | does autovacuum in postgres-8.1.2 use prepared transactions ?? |