sql - PostgreSQL: Why is NOT NULL not working here? -


I am developing my first application with PostgreSQL.

Scenario

My table "person" looks like this:

  column | Type | Modifier ------------ + ----------------------------- + ------ ----------------------------------------------- ID Big IT | Null default to next ('person_id_seq' :: regclass no) first_name | Character different (255) | No last_name | Character different (255) | No email. Character different (255) | No password. Character different (255) | Taps were not made. Timestamp without time zone. Updated_at | Timestamp without time zone. Index: "person_pkey" primary key, BTRI (id) "person_memel_inic" unique contract, BTRI (email) "person_id_unique" unique content, referenced by btry (id): table "access" contract "access_ person_id_foreign" foreign key (person_id) reference person (Id)  

This was created using the migration.

If I run the following query in psql ...

In the person insert (first_name, last_name, email, password) value ('max', 'musimanan' , '', '123123123');

I returned INSERT 0 1 and the row has been successfully entered:

  id | First_name | Last_name Email | Password | Created_at | Updated_at ---- + ------------ + ------------ + ------------------ ----------------- + ---------------- + --------------- ---------- + ------------------------- 12 | Max | Mostman | | 123123123 | |  

My question:

I hope the operation fails, because no e-mail was specified (not null). Why is not this unsuccessful?

Thank you very much for your help!

some DBMS (like Oracle) empty string ( ' ') as the NULL . Others (such as MySQL, PostgreSQL, etc.) treat different types as empty strings and NULL .

PostgreSQL treats '' as empty string, not NULL , so your insert statement successfully executed Gaya.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -