Insert into PrimaryKey_demo values (1, current_date, 'test1') - Duplicate valueĪbove statement will execute perfectly despite of having primary key constraints on table. Insert duplicate value to a table that has primary key defined insert into PrimaryKey_demo values (1, current_date, 'test1') -This 1st value You can insert the duplicate values in Redshift tables. Now, let us test if the Primary key is enforced. With a minimal changes you can same DDL to create a table on Redshift.Īmazon Redshift does enforce NOT NULL column constraints.Īmazon Redshift Does Not Enforce Primary Key Moreover, it is really easy to migrate database to the Amazon Redshift that has constraints defined on the table. On the other hand, you should always declare primary and foreign keys and uniqueness constraints when you know that they are valid. Redshift recommends not to define key constraints for your tables if you doubt their validity. By doing this, it can order large numbers of joins and eliminate redundant joins. It uses this primary key, foreign key to infer uniqueness and referential relationships that affect subquery decorrelation techniques. The optimizer uses these hints to generate an optimal query execution plan.įor example, the Redshift query planner uses primary and foreign keys in certain statistical computations. The primary keys and foreign keys are used as planning hints. They should be declared if your ETL process or some other process in your application enforces their integrity. Primary key, foreign key and unique keys are informational only. Table level primary key: create table PrimaryKey_demo2 (Ĭompound sortkey(col1, col2) How Amazon Redshift Uses Primary key? You can mention the primary key constraint when creating table either on column level or on table level:Ĭolumn level primary key: create table PrimaryKey_demo (
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |