Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table column of type timestamp without milliseconds?

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()
    );
like image 990
Alan Yu Avatar asked Jan 02 '14 05:01

Alan Yu


1 Answers

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.

like image 181
Pavel Stehule Avatar answered Nov 01 '22 02:11

Pavel Stehule