0

I am reading the Postgres 7.3 documentation to add a constraint to a PostgreSQL table.

It says:

To add a not-null constraint, which cannot be written as a table constraint, use this syntax:

ALTER TABLE products ALTER COLUMN product_no SET NOT NULL;

The constraint will be checked immediately, so the table data must satisfy the constraint before it can be added.

I don't understand what it means by "which cannot be written as a table constraint"?

What is table constraint? What constraint doesn't check immediately?

1
  • Why are you reading such an outdated version of the manual?
    – user1822
    Feb 22, 2022 at 6:17

1 Answer 1

2

That's just a question of syntax.

A column constraint is defined like

CREATE TABLE ... (
   col type [CONSTRAINT name] constraint_definition,
   ...
);

while a table constraint look like

CREATE TABLE ... (
   col type,
   [CONSTRAINT name] constraint_definition,
   ...
);

The resulting constraint is the same in both cases.

So the documentation is saying that you need to write NOT NULL in the column definition and you cannot write it anywhere else.

0

Your Answer

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

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