Syntax to remove a default value on a table column

Moderator: NorbertKrupa

Post Reply
User avatar
fsalvelt
Intermediate
Intermediate
Posts: 54
Joined: Sun Mar 18, 2012 1:34 am

Syntax to remove a default value on a table column

Post by fsalvelt » Wed Mar 11, 2015 9:37 pm

Hi,

I can't figure out how to remove a default value from a table column. Say for example I have this table:

Code: Select all

dbadmin=> create table t (a int default 1);
CREATE TABLE
dbadmin=> select column_name, column_default from columns where table_name = 't';
 column_name | column_default
-------------+----------------
 a           | 1
(1 row)
I tried the following syntax to remove the default:

Code: Select all

dbadmin=> alter table t alter column a set default;
ERROR 4856:  Syntax error at or near ";" at character 41
LINE 1: alter table t alter column a set default;
                                                ^
dbadmin=> alter table t alter column a set default '';
ROLLBACK 3681:  Invalid input syntax for integer: ""
Anyone know the correct syntax?
Thank, Fred

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Syntax to remove a default value on a table column

Post by JimKnicely » Wed Mar 11, 2015 10:21 pm

The "default" default for a column is NULL. Just set it back to NULL:

alter table t alter column a set default null;
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Syntax to remove a default value on a table column

Post by JimKnicely » Thu Mar 12, 2015 2:44 pm

fsalvelt,

Ignore that last suggestion by user knicely87! Use the ALTER TABLE ALTER COLUMN DROP DEFAULT command instead:

Code: Select all

dbadmin=> create table t (a int default 1);
CREATE TABLE

dbadmin=> alter table t alter column a drop default;
ALTER TABLE
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica SQL”