Re: Get Unix timestamp from SQL timestamp through libpq

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
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 11:41:45
Message-ID: 80B7B558-F71D-45C5-9EA4-39B7646F0A41@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 you go 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'd have 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!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message tamanna madaan 2010-01-11 11:59:54 does autovacuum in postgres-8.1.2 use prepared transactions ??
Previous Message Ivan Sergio Borgonovo 2010-01-11 11:35:56 Re: R: aggregate over tables in different schema