Hi, Is It possible to add new column in table after checking whether column already exists or not?Ap

Hi, Is It possible to add new column in table after checking whether column already exists or not?Appreciate your help. Thank you.

Comments

  • Hi,


    If I understood it correctly, you want that vertica first check if the newly added column is already there in table or not?
    So if I have a table TAB with below definition
     Schema | Table | Column  |    Type     | Size | Default | Not Null | Primary Key | Foreign Key
    --------+-------+---------+-------------+------+---------+----------+-------------+-------------
     public | TAB        | name    | varchar(10) |   10 |         | f        | f           |
     public | TAB         | desg    | varchar(10) |   10 |         | f        | f           |

    Then if I try to add a new column "name", then it will throw a warning

    gl=> alter table TAB add column name varchar(10);
    ROLLBACK 3145:  Duplicate column name

    Please let me know if this is what you were asked

    Thanks


  • Prasanta_PalPrasanta_Pal - Select Field - Employee
    dbadmin=>\d <table_name> will give the details of the table along with column names and data type, you can verify there if your newly added column  or simple run 'select * from <table_name> limit 0;' and also Shobhit showed that if you want add a duplicate column, it will throw error.
    Hope this answers your query if not let us know what you are looking for, we would be glad to help you.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file