Обсуждение: any way to convert date via libpq?

Поиск
Список
Период
Сортировка

any way to convert date via libpq?

От
"Tena Sakai"
Дата:

Hi Everybody,

I have a C program to read a postgres table.  One of
the columns of this table is defined as:

  timestamp without time zone

Is there any routine/function that I can use to convert
this field/column value into unix/linux style date for
comparison purpose?

Thank you.

Regards,

Tena Sakai
tsakai@gallo.ucsf.edu

Re: any way to convert date via libpq?

От
Scott Marlowe
Дата:
On Tue, Mar 10, 2009 at 8:43 PM, Tena Sakai <tsakai@gallo.ucsf.edu> wrote:
> Hi Everybody,
>
> I have a C program to read a postgres table.  One of
> the columns of this table is defined as:
>
>   timestamp without time zone
>
> Is there any routine/function that I can use to convert
> this field/column value into unix/linux style date for
> comparison purpose?

select extract('epoch' from timestampfield) ;

Re: any way to convert date via libpq?

От
"Tena Sakai"
Дата:

Hi Scott,

Many thanks for your reply.
I just tried:
  select extract (epoch from timestamp with time zone '2008-04-04 20:00:0.0');
and got:
  1207364400
which is great!

I suppose there is no problem running this query
via PGexec() in a C program?  Something like:
  result = PGexec (conn, "FETCH ALL from somePort");

Many thanks.

Regards,

Tena Sakai
tsakai@gallo.ucsf.edu

-----Original Message-----
From: Scott Marlowe [mailto:scott.marlowe@gmail.com]
Sent: Tue 3/10/2009 9:55 PM
To: Tena Sakai
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] any way to convert date via libpq?

On Tue, Mar 10, 2009 at 8:43 PM, Tena Sakai <tsakai@gallo.ucsf.edu> wrote:
> Hi Everybody,
>
> I have a C program to read a postgres table.  One of
> the columns of this table is defined as:
>
>   timestamp without time zone
>
> Is there any routine/function that I can use to convert
> this field/column value into unix/linux style date for
> comparison purpose?

select extract('epoch' from timestampfield) ;

Re: any way to convert date via libpq?

От
Scott Marlowe
Дата:
On Wed, Mar 11, 2009 at 12:07 AM, Tena Sakai <tsakai@gallo.ucsf.edu> wrote:
> Hi Scott,
>
> Many thanks for your reply.
> I just tried:
>   select extract (epoch from timestamp with time zone '2008-04-04
> 20:00:0.0');
> and got:
>   1207364400
> which is great!
>
> I suppose there is no problem running this query
> via PGexec() in a C program?  Something like:
>   result = PGexec (conn, "FETCH ALL from somePort");

It's definitely accessable by anything connecting to the db.  Not sure
how that's done in C so someone else will have to chip in on that.