Question

I want to create a table have(id,time) and time (timestamp without timezone) without milliseconds.
And I also want to insert the current time per default.

CREATE TABLE ddd (
    id          serial not null,         
    time        timestamp without time zone default now()
    );
Was it helpful?

Solution

Specify a precision:

postgres=# CREATE TABLE foo(a timestamp(0));
CREATE TABLE
postgres=# INSERT INTO foo VALUES(CURRENT_TIMESTAMP);
INSERT 0 1
postgres=# SELECT * FROM foo;
          a          
---------------------
 2014-01-02 07:26:23
(1 row)

Small note - "time" is a bad name for table field (I understand this is example). Any field name should have a specific semantic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top