As someone who came here with the same question, I am not sure what to do with these answers. I tried all of them and always got a syntax error "next to" with one or another term. Returning to the official docs , I realized that there was no additional keyword, such as SET or TYPE. Examples:
First it
zuri=# ALTER TABLE newarts ALTER COLUMN sunsetdate DATE NULL; ERROR: syntax error at or near "DATE" LINE 2: ALTER COLUMN sunsetdate DATE NULL;
Then this:
zuri=# ALTER TABLE newarts ALTER COLUMN sunsetdate TYPE DATE NULL; ERROR: syntax error at or near "NULL" LINE 2: ALTER COLUMN sunsetdate TYPE DATE NULL;
Yes, there is still an error, but as soon as I specified the DATE value with the TYPE keyword, the error was resolved and I moved on to another. I had the same experience with the addition of SET (see Examples on the same page of white papers that I already quoted).
Regarding the specific NOT NULL problem (especially regarding my date of dates), I read this answer and it seemed to work - I did not receive the error message -
zuri=
But then I read
On success, the UPDATE command returns the form command tag
UPDATE count
Number is the number of rows updated. If count is 0, there are no lines (this is not considered an error).
What is also in the official docs here .
Finally, I turned to PGAdminIII, where I found that NOT NULL is a simple flag. Uncheck the box, the problem is resolved. I am sure there is a way to make this work on the command line with psql, I just did not find it.
I think that some of the options can also be related to the differences between ALTER and UPDATE (see this SO answer and my daring comment), as well as between adding new structures (as in the OP question) and changing data that already exists (like I have). The moral of the story, read the official documentation. Do not scan it. Read. And if you want to know more about NULL and NOT NULL, read this .
Malik A. Rumi
source share