create foreign key only if it doesn't exits

Hello ,

is there any way to achieve the following in vertica?

alter table add constraint fk_table IF NOT EXISTS foreign key (col) references ....;


Comments

  • I was able to acheive this by using the following approach 

    \set fk_sql  'vsql -t -c "SELECT decode(count(*),0,'alter table temp2 ADD CONSTRAINT FK_TEMP2    FOREIGN KEY (ID)  REFERENCES TEMP1(ID)',null) as Cnt FROM v_catalog.constraint_columns where table_name='temp2' and constraint_name='temp_fk' ;"'

     --- execute the sql stored in variable

     :fk_sql;

Leave a Comment

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