I have the following DB schema in MySQL, which I have replicated in PostgreSQL using an ORM:
CREATE TABLE IF NOT EXISTS users (
id BIGINT NOT NULL DEFAULT NEXTVAL ('users_seq'),
email VARCHAR(255) NOT NULL DEFAULT '',
password VARCHAR(255) NOT NULL DEFAULT '',
last_name VARCHAR(255) NOT NULL DEFAULT '',
first_name VARCHAR(255) NOT NULL DEFAULT '',
created TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
And I'm trying to execute the following query
INSERT INTO users (id, email, password,first_name, last_name, created, updated)
VALUES (1, '[email protected]', 'pass', 'user', 'user', NULL, NULL);
This results in an error
ERROR: null value in column "created" violates not-null constraint
Expected behaviour is to have the current timestamp in case the value is NULL, and it works in MySQL
I'm using PostgreSQL 10. Am I missing any configuration or is this not supported in Postgres?
NULL- it will inert NULL, notDEFAULTcreatedandupdatedfields, you are trying to insert null into non nullable fields. Only default will will insert if your insert query don't have this fieldENGINE = InnoDB, etc). I have edited the question to say that this is the MySQL version you have replicated, but you might want to edit to provide the actual PostgresCREATE TABLEstatement instead.