Search code examples
sqlpostgresqlconstraints

PostgreSQL: How to make values obligatory in INSERT querys?


I'm trying to create a table with Postgresql, in which the value of name is required. That means, if i intend to make an INSERT, i'd be obligated to fill the value of name.

I'm trying to create like that:

CREATE TABLE person (
  id SERIAL,
  name VARCHAR(64),
  height REAL,
  PRIMARY KEY(id)
)

I don't know if there is a "REQUIRED" in SQL, but in my researchs i still didn't find it.


Solution

  • As Serg and Jeroen Mostert pointed in the comments, i only had to make it NOT NULL, so it went out like that:

    CREATE TABLE person (
      id SERIAL NOT NULL,
      name VARCHAR(64) NOT NULL,
      height REAL NOT NULL,
      PRIMARY KEY(id)
    )