Using Compound Predicate Joins
Vertica allows tables to have compound (multiple-column) primary and foreign keys. For example:
-- Create a pair of tables with multi-column keys
CREATE TABLE dimension
(pk1 INTEGER NOT NULL,
pk2 INTEGER NOT NULL);
ALTER TABLE dimension
ADD PRIMARY KEY (pk1, pk2);
CREATE TABLE fact
(fk1 INTEGER NOT NULL,
fk2 INTEGER NOT NULL);
ALTER TABLE fact
ADD FOREIGN KEY (fk1, fk2)
REFERENCES dimension (pk1, pk2);
To join tables using compound keys, you must connect two
join predicates with a Boolean AND operator. For example:
Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information.
Syntax
column-reference =
column-reference
Syntax
[ tablename. ] columnname
Semantics
tablename
|
is one of:
- the name of a table
- an alias for a table defined by means of a FROM clause in a query
|
columnname
|
is the name of a column that must be unique across all the tables being used in a query
|
Notes
- There are no space characters in a column reference.
Syntax
[ tablename. ] columnname
Semantics
tablename
|
is one of:
- the name of a table
- an alias for a table defined by means of a FROM clause in a query
|
columnname
|
is the name of a column that must be unique across all the tables being used in a query
|
Notes
- There are no space characters in a column reference.
Semantics
column-reference
|
refers to a column of one the tables specified in the FROM clause.
|
Notes
- Self-joins are not allowed.
-- Query that joins the tables
SELECT *
FROM fact, dimension
WHERE fact.fk1 = dimension.pk1
AND
fact.fk2 = dimension.pk2;