- Newest
- Most votes
- Most comments
Hi,
This happens by design: https://docs.aws.amazon.com/redshift/latest/dg/t_Defining_constraints.html says:
Uniqueness, primary key, and foreign key constraints are informational only; they
are not enforced by Amazon Redshift. Nonetheless, primary keys and foreign keys
are used as planning hints and they should be declared if your ETL process or some
other process in your application enforces their integrity.
Best,
Didier
The scenario you've described should indeed cause an error, but it's not behaving as expected. This is likely due to a misunderstanding or a potential issue with your database system.
In a properly functioning relational database system, attempting to insert a duplicate value into a column defined as a PRIMARY KEY should result in an error. The PRIMARY KEY constraint ensures that each value in that column is unique across all rows in the table.
In your example:
- You're creating a table
d_datewithdate_skas the PRIMARY KEY. - You're inserting two rows with the same
date_skvalue (1).
The second INSERT statement should fail with a primary key violation error. If it's not, there could be several reasons:
- The PRIMARY KEY constraint might not have been properly applied when creating the table.
- There might be an issue with your database configuration or settings.
- You might be using a database system that doesn't enforce PRIMARY KEY constraints strictly (which would be unusual for a production-grade relational database).
To troubleshoot this:
- Double-check that the PRIMARY KEY constraint was successfully created with the table.
- Try running a DESCRIBE or similar command on your table to verify its structure.
- Ensure you're connected to the correct database and schema.
- If possible, try to recreate this scenario in a different database instance to see if the behavior persists.
If the issue continues, you may need to consult your database system's documentation or support channels, as this behavior is not standard and could indicate a more serious problem with your database setup or configuration.
Sources
DROP TABLE - Amazon Redshift
Error handling for T-SQL - SQL Server to Aurora PostgreSQL Migration Playbook
here is table ddl:
CREATE TABLE IF NOT EXISTS public.d_date
(
date_sk INTEGER NOT NULL ENCODE az64
,date_id DATE ENCODE az64
,PRIMARY KEY (date_sk)
)
DISTSTYLE AUTO
;
answered 2 years ago
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 months ago
