Re: Get Unix timestamp from SQL timestamp through libpq - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Get Unix timestamp from SQL timestamp through libpq
Date
Msg-id 80B7B558-F71D-45C5-9EA4-39B7646F0A41@solfertje.student.utwente.nl
Whole thread Raw
In response to Get Unix timestamp from SQL timestamp through libpq  (Yan Cheng Cheok <yccheok@yahoo.com>)
List pgsql-general
On 11 Jan 2010, at 7:16, Yan Cheng Cheok 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. 

The format of that "timestamp" you're referring to is dependant on client and server settings (locale among others). If
yougo this way make sure you specify the format when making the connection. 

Another option is to add an extra epoch column to your result-row and return that row instead of the original row.
You'dhave to change the return type to include the extra column of course (see RETURNS TABLE in the docs). 

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4b4b0e7a10733449211764!



pgsql-general by date:

Previous
From: Ivan Sergio Borgonovo
Date:
Subject: Re: R: aggregate over tables in different schema
Next
From: Merlin Moncure
Date:
Subject: Re: Get Unix timestamp from SQL timestamp through libpq