We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


create foreign key only if it doesn't exits — Vertica Forum

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