MySQL 有一些功能,但 postgresql 没有。1.创建表并赋予列默认值 2.向表中插入空值。在MySQL中它将插入默认值;在postgresql中它将插入空值;我怎样才能让 postgresql 做像 MySQL 一样的事情。我在更改DBMS期间发现了这个问题。我的应用程序是java代码。ORM 是 Hibernate 5.1.0。我更改了 DBMS,然后很多默认列都不起作用。
MySQL 数据库
drop table table1;
CREATE TABLE table1
(
column_1 int PRIMARY KEY AUTO_INCREMENT,
column_2 timestamp DEFAULT current_timestamp
);
insert into table1(column_2) values(null);
select * from table1;
Run Code Online (Sandbox Code Playgroud)
结果
| column_1 | column_2 |
+----------+---------------------+
| 1 | 2018-04-24 10:00:18 |
Run Code Online (Sandbox Code Playgroud)
pgsql
drop table table2;
CREATE TABLE table2
(
column_1 serial PRIMARY KEY,
column_2 timestamp DEFAULT current_timestamp
);
insert into table2(column_2) values (null);
select * from table2;
Run Code Online (Sandbox Code Playgroud)
结果 …