6

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()
    );
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Alan Yu
  • 1,462
  • 12
  • 21
  • Related answers that may be of help [here](http://stackoverflow.com/questions/10213190/discard-millisecond-part-from-timestamp/10213289#10213289), [here](http://stackoverflow.com/questions/8973753/date-compare-in-postgresql/8973915#8973915) or [here](http://stackoverflow.com/questions/13555736/allow-only-work-time-in-reservations-table/13556206#13556206). – Erwin Brandstetter Jan 02 '14 at 10:34

1 Answers1

21

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.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94