Thread: /contrib/unixdate: Broke in cvs tip.

/contrib/unixdate: Broke in cvs tip.

From
Larry Rosenman
Date:
I tried to use the unixdate contrib, and got the following:

attack=# \i unixdate.sql
psql:unixdate.sql:21: ERROR:  ProcedureCreate: there is no builtin
function named "-"
psql:unixdate.sql:25: ERROR:  Function 'abstime_datetime(int4)' does
not exist       Unable to identify a function that satisfies the given
argument types       You may need to add explicit typecasts
psql:unixdate.sql:29: ERROR:  ProcedureCreate: there is no builtin
function named "-"
psql:unixdate.sql:33: ERROR:  Function 'reltime_timespan(int4)' does
not exist       Unable to identify a function that satisfies the given
argument types       You may need to add explicit typecasts
attack=# 


Any ideas? (I need SOMETHING that takes a unix timestamp and turns it
to timestamp. )


Thanks!

-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: /contrib/unixdate: Broke in cvs tip.

From
Tom Lane
Date:
Larry Rosenman <ler@lerctr.org> writes:
> I tried to use the unixdate contrib, and got the following:

I think unixdate is suffering from bit-rot.  Most or all of what it
does is now part of the mainframe anyway.

> Any ideas? (I need SOMETHING that takes a unix timestamp and turns it
> to timestamp. )

There are a number of ways.  I tend to rely on the binary equivalence
between int4 and abstime:

regression=# select now()::abstime::int4;?column?
-----------991145365
(1 row)

regression=# select 991145365::int4::abstime::timestamp;       ?column?
------------------------2001-05-29 10:09:25-04
(1 row)

but the more officially supported way to do the former is
date_part('epoch', timestamp), and I think there is also an
Approved Way to do the latter.  (Thomas?)
        regards, tom lane


Re: /contrib/unixdate: Broke in cvs tip.

From
Larry Rosenman
Date:
* Tom Lane <tgl@sss.pgh.pa.us> [010529 10:07]:
> Larry Rosenman <ler@lerctr.org> writes:
> > I tried to use the unixdate contrib, and got the following:
> 
> I think unixdate is suffering from bit-rot.  Most or all of what it
> does is now part of the mainframe anyway.
Aha!  I couldn't find what I needed...
> 
> > Any ideas? (I need SOMETHING that takes a unix timestamp and turns it
> > to timestamp. )
> 
> There are a number of ways.  I tend to rely on the binary equivalence
> between int4 and abstime:
> 
> regression=# select now()::abstime::int4;
>  ?column?
> -----------
>  991145365
> (1 row)
> 
> regression=# select 991145365::int4::abstime::timestamp;
>         ?column?
> ------------------------
>  2001-05-29 10:09:25-04
> (1 row)
This ugly one worked for me, but I'd still like to see
a more general way to move from a unix timestamp to datetime with out
the 3 casts....
> 
> but the more officially supported way to do the former is
> date_part('epoch', timestamp), and I think there is also an
> Approved Way to do the latter.  (Thomas?)
Thanks again, Tom!

LER

-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749