rimas
rimas

Reputation: 757

How insert time_t into PostgreSQL timestamp field

How to insert time/date received into time_t structure into column which has 'timestamp without timezone' type?

Previously I was using int8 as data type and time_t perfectly fits but I would like to know how to do it with timestamp field(preferably without casting time_t to string from caller program) using PQexecParams call.

Upvotes: 2

Views: 4711

Answers (1)

Daniel Vérité
Daniel Vérité

Reputation: 61666

Use the to_timestamp function. Example:

 select to_timestamp(1000000000)::timestamp;

Result:

   to_timestamp     
---------------------  
 2001-09-09 03:46:40
1 row) 

Upvotes: 5

Related Questions