0

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).

2

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, privacy policy and cookie policy

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