Alternative to CHECK

Moderator: NorbertKrupa

Post Reply
Rick
Newbie
Newbie
Posts: 23
Joined: Thu Jul 26, 2012 2:46 pm

Alternative to CHECK

Post by Rick » Mon Jul 30, 2012 2:08 pm

I'm running Vertica 5, and i noticed that when making tables, vertica apparantly doesn't support CHECK constraints. I was wondering if there is any alternative to this in vertica?
Thanks

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Alternative to CHECK

Post by id10t » Mon Jul 30, 2012 2:34 pm

Hi!


>>I was wondering if there is any alternative to this in vertica?
No. Only ANALYZE_CONSTRAINTS - http://my.vertica.com/docs/6.0.0-1/HTML ... #11175.htm
Also - http://www.vertica-forums.com/viewtopic ... =101&p=143

Rick
Newbie
Newbie
Posts: 23
Joined: Thu Jul 26, 2012 2:46 pm

Re: Alternative to CHECK

Post by Rick » Tue Jul 31, 2012 9:21 am

Thanks :)

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

Re: Alternative to CHECK

Post by JimKnicely » Tue Jul 31, 2012 2:17 pm

I'm curious about how you guys feel about creating a look up table that stores the "permitted" values for a column and then using an FK and a projection to disallow any values to be stored in the base table that would typically have a CHECK constraint in other databases.

Here's a simple example where I only want to permit the values of "Y" or "N" to be stored in the col1 column of the test table:

Code: Select all

dbadmin=> create table test_lookup (col1 varchar(1) primary key);
CREATE TABLE
dbadmin=> create table test (col1 varchar(1) not null references test_lookup);
CREATE TABLE
dbadmin=> create projection test_pj as select * from test join test_lookup on test_lookup.col1 = test.col1 unsegmented all nodes;
CREATE PROJECTION
dbadmin=> insert into test_lookup values ('Y');
 OUTPUT
--------
      1
(1 row)

dbadmin=> insert into test_lookup values ('N');
 OUTPUT
--------
      1
(1 row)

dbadmin=> insert into test values ('Y');
 OUTPUT
--------
      1
(1 row)

dbadmin=> insert into test values ('X');
ERROR 4165:  Nonexistent foreign key value detected in FK-PK join [(public.test x public.test_lookup) using subquery and test_lookup_b0 (PATH ID: 1)]; value [X]
Although, I suppose using this methodology would snowflake the data model out of control! Plus, in the end, I think that the ETL process should make sure only the desired values are stored in our fact tables and that we shouldn't rely on Vertica to enforce check constraints.
Jim Knicely

Image

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

Rick
Newbie
Newbie
Posts: 23
Joined: Thu Jul 26, 2012 2:46 pm

Re: Alternative to CHECK

Post by Rick » Thu Aug 02, 2012 3:31 pm

Nice idea, could get messy though with large databases!

Post Reply

Return to “Vertica SQL”