3

Snowflake offers a Unique constraint but doesn't actually enforce it. I have an example below showing that with a test table.

  1. What is the point, what value does the constraint add?
  2. What workarounds do people use to avoid duplicates? I can perform a query before every insert but it seems like unnecessary usage.
CREATE OR REPLACE TABLE dbo.Test
(
  "A" INT NOT NULL UNIQUE,
  "B" STRING NOT NULL
);

INSERT INTO dbo.Test
VALUES (0, 'ABC');

INSERT INTO dbo.Test
VALUES (0, 'DEF');

SELECT *
FROM dbo.Test;

1. A, B
2. 0, ABC
3. 0, DEF
jacobvoller.com
  • 476
  • 7
  • 28
  • Does this answer your question? [Significance of Constraints in Snowflake](https://stackoverflow.com/questions/59725414/significance-of-constraints-in-snowflake) –  Jul 05 '20 at 01:03

1 Answers1

1
  1. for one, Snowflake is not alone in this world. So data gets imported and exported, and while Snowflake does not enforce the constraints, some other systems might and this way they won't get lost while travelling through Snowflake

for other, it's also informational for the data analytical tools like already mentioned in the link Kirby provided

  1. please remember, that execution is consecutive, so running a check before every query will still get you duplicates at high concurrency. To avoid duplicates fully you need to either run merges (which is admittedly going to be slower) or manually delete the "excessive" data after it's been loaded
MMV
  • 920
  • 4
  • 9