postgresql - Default timestamp format and fractional seconds -
i'm trying format timestamps in postgres database format:
yyyy-mm-dd hh24:mi:ss by doing:
update mytable set tds = to_char(tds, 'yyyy-mm-dd hh24:mi:ss')::timestamp; i managed set stored tds format. however, newly added entry goes to: yyyy-mm-dd hh24:mi:ss.ms since default set now().
how change newly added entries have format: yyyy-mm-dd hh24:mi:ss?
there no format stored in timestamp type. can set default timestamp truncated second @ creation time
create table t ( tds timestamp default date_trunc('second', now()) ) or alter table
alter table t alter column tds set default date_trunc('second', now()); insert t values (default); insert 0 1 select * t; tds --------------------- 2014-03-11 19:24:11 if don't want show milliseconds part format output
select to_char(now(), 'yyyy-mm-dd hh24:mi:ss'); to_char --------------------- 2014-03-11 19:39:40
Comments
Post a Comment