ALTER TABLE, set null in not null column, PostgreSQL 9.1


Tengo una tabla con columna not null, ¿Cómo establecer un valor null en esta columna como predeterminado?

Quiero decir, quiero hacer algo como esto:

postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL;

Pero muestra:

postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL;
ERROR:  syntax error at or near "NULL"
LINE 1: ALTER TABLE person ALTER COLUMN phone SET NULL;
Author: Brian Brown, 2012-11-30

4 answers

ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;

Más detalles en el manual: http://www.postgresql.org/docs/9.1/static/sql-altertable.html

 121
Author: a_horse_with_no_name,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-30 11:03:21

Ejecute el comando en este formato

ALTER TABLE tablename ALTER COLUMN columnname SET NOT NULL;

Para establecer la columna en not null.

 17
Author: Rigin Oommen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-30 09:04:24
First, Set :
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;
 11
Author: jainvikram444,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-06 04:57:59

Ejecutar el comando en este formato:

ALTER [ COLUMN ] column { SET | DROP } NOT NULL

 0
Author: Sunny Chawla,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-19 07:38:13