pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedconverting time_t to timestamp?
2+ messages / 2 participants
[nested] [flat]
* converting time_t to timestamp?
@ 2003-03-12 02:57 patrick <patrick+pgsql@boxsoft.com>
0 siblings, 1 reply; 2+ messages in thread
From: patrick @ 2003-03-12 02:57 UTC (permalink / raw)
To: pgsql-sql
Greetings,
I'm reposting this question since I received zero replies from my
original post (maybe the original subject line was misleading).
I've just^W upgraded from PostgreSQL 7.1.2 to 7.3.2.
In 7.1.2 I was able to use the output of time(2) (and the like) to
insert into a field of timestamp type.
First thing i noticed with the upgrade was that the following broke:
in 7.1.2
=> select timestamp ( 1046923200 );
timestamp
------------------------
2003-03-05 20:00:00-08
(1 row)
in 7.3.2
=> select timestamp ( 1046923200 );
ERROR: TIMESTAMP(1046923200) precision must be between 0 and 6
Can anyone point me to a work-around?
I notice that I can use abstime( 1046923200 ) to get the desired
result. But is this the optimal way to do this?
My client application uses mktime(3) and then forms the SQL
statement to insert into a table of the form:
sprintf( sql_stmt,
"insert into tab1 "
" ( ... , target_timestamp, ... ) "
"values ( ... , timestamp( %lu ), ... ) ",
...,
mktime( &tm ) );
/*
* You get the idea.
*/
Thanks in advance,
sidster
--
They who would sacrifice freedom for security will have neither.
-Ben Franklin
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: converting time_t to timestamp?
@ 2003-03-12 04:42 Stephan Szabo <sszabo@megazone23.bigpanda.com>
parent: patrick <patrick+pgsql@boxsoft.com>
0 siblings, 0 replies; 2+ messages in thread
From: Stephan Szabo @ 2003-03-12 04:42 UTC (permalink / raw)
To: patrick <patrick+pgsql@boxsoft.com>; +Cc: pgsql-sql
On Tue, 11 Mar 2003, patrick wrote:
> I'm reposting this question since I received zero replies from my
> original post (maybe the original subject line was misleading).
> I've just^W upgraded from PostgreSQL 7.1.2 to 7.3.2.
>
> In 7.1.2 I was able to use the output of time(2) (and the like) to
> insert into a field of timestamp type.
>
> First thing i noticed with the upgrade was that the following broke:
The old syntax somewhat conflicted with the full type specifier when we
added the precision stuff. Unfortunately, the change caught alot of
people. :(
>
> in 7.1.2
> => select timestamp ( 1046923200 );
> timestamp
> ------------------------
> 2003-03-05 20:00:00-08
> (1 row)
>
> in 7.3.2
> => select timestamp ( 1046923200 );
> ERROR: TIMESTAMP(1046923200) precision must be between 0 and 6
>
>
> Can anyone point me to a work-around?
>
> I notice that I can use abstime( 1046923200 ) to get the desired
> result. But is this the optimal way to do this?
'epoch'::timestamp + (<integer> * '1 second'::interval);
seems more explicit to me (in its intention), but probably isn't as
efficient as the int4->abstime->timestamp path.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-03-12 04:42 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-03-12 02:57 converting time_t to timestamp? patrick <patrick+pgsql@boxsoft.com>
2003-03-12 04:42 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox