I am trying to run an ALTER
query in Snowflake to add a column TEST_COL
, if it does not exists already in the table TEST_SALES
.
I would like to set a DEFAULT
value of 'N' for the column as well.
This is the query I used:
ALTER TABLE TEST_SALES
ADD COLUMN IF NOT EXISTS TEST_COL VARCHAR(1) DEFAULT 'N';
On rerunning the same query, it throws this error:
SQL Error [2028] [42601]: SQL compilation error: ambiguous column name 'TEST_COL'
Is there a solution?
Please note that it allows me to rerun any number of times, if I do not set the default value
Query used is:
ALTER TABLE TEST_SALES
ADD COLUMN IF NOT EXISTS TEST_COL VARCHAR(1);
DEFAULT
is not allowed withIF NOT EXISTS
when adding a column :From Docs :