Less Than Constraint for a Column in Vertica

Moderator: NorbertKrupa

Post Reply
varuna.bhat
Newbie
Newbie
Posts: 5
Joined: Fri May 31, 2013 9:15 pm

Less Than Constraint for a Column in Vertica

Post by varuna.bhat » Fri May 31, 2013 10:07 pm

Hello,

I am migrating some tables from oracle to vertica and i have some less than constraints created on some columns in oracle(for e.g CONSTRAINT "EMP_SALARY_MIN" CHECK (salary > 0) ENABLE,).

How I can add same constraint in vertica while creating the table ?

Thanks-

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

Re: Less Than Constraint for a Column in vertica

Post by JimKnicely » Tue Jun 04, 2013 10:37 pm

Hi,

Vertica does not support check constraints. You should try to check the data before you load it into Vertica during the ETL process.

But, there is also a quirky work around you can do with your table. But I wouldn't recommend it in production because it'll degrade performance.

Anyway, you can add an extra column to the table to check the value... Like this:

Code: Select all

dbadmin=> create table jim (c1 int);
CREATE TABLE

dbadmin=> alter table jim add column c2 int default 1 / decode(sign(c1), 1, 1, 0);
ALTER TABLE

dbadmin=> insert into jim (c1) values (1);
 OUTPUT 
--------
      1
(1 row)

dbadmin=> insert into jim (c1) values (0);
ERROR 3117:  Division by zero

dbadmin=> insert into jim (c1) values (-1);
ERROR 3117:  Division by zero
See how I could not insert a 0 or -1?
Jim Knicely

Image

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

varuna.bhat
Newbie
Newbie
Posts: 5
Joined: Fri May 31, 2013 9:15 pm

Re: Less Than Constraint for a Column in Vertica

Post by varuna.bhat » Tue Jun 04, 2013 11:54 pm

Thanks Jim for your reply.

Post Reply

Return to “New to Vertica SQL”