I want to create a table which has a column named "direction".

This column is either "in" or "out". It is not nullable and it can only contain these two values. Never other values.

Which data type is most feasible?

I use in PostgreSQL. It is 100% ok if the data type is PG specific (only known to this database implementation).


1 Answer 1


You can create an enumerated type for this:

CREATE TYPE direction AS ENUM ('in', 'out');

CREATE TABLE a_table (
  ID        serial,
  direction direction NOT NULL

INSERT INTO a_table (direction) VALUES ('in');        -- succeeds
INSERT INTO a_table (direction) VALUES ('sideways');  -- fails

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.