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()
    );
Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top