0

I created this query and now that I put it in an automation, but I keep getting the error:

ERROR: Violation of PRIMARY KEY constraint. Cannot insert duplicate key.

enter image description here enter image description here

MY SQL:


SELECT DISTINCT  J.JourneyID,
                 J.VersionID,
                 J.JourneyName,
                 J.VersionNumber,
                 J.LastPublishedDate,
                 J.ModifiedDate,
                 J.CreatedDate, 
                 J.JourneyStatus, 
                 JA.ActivityID,
                 JA.ActivityName,
                 JA.ActivityExternalKey,
                 JA.JourneyActivityObjectID,
                 JA.ActivityType
FROM _Journey J
INNER JOIN _JourneyActivity JA ON JA.VersionID = J.VersionID
WHERE CreatedDate BETWEEN '2022-01-01' AND DATEADD(day, -1, GETDATE())

4
  • 2
    My suggestion would be to remove your PK field constraint and run your query and review the data you have
    – EazyE
    Commented May 11, 2023 at 21:10
  • What would this PK field restriction be? I already tried to create with the destination DE without a PK but it requires a PK @EazyE Commented May 12, 2023 at 12:39
  • @ThaisCarolyne you can remove the primary key field and use the query type "Overwrite" and then try again
    – Duc Le
    Commented May 12, 2023 at 15:04
  • It worked out! Could you write your suggestion for my problem as an answer to my question? so I could mark as correct answer and close the question @DucLe Commented May 15, 2023 at 19:42

1 Answer 1

0

Because a journey may have multiple journey versions and multiple journey activities, when you set the JourneyID field as a Primary Key field (force the value in this field to be unique), this may conflict with your SQL result.

My suggestion would be:

  1. Remove the primary key field on the JourneyID field
  2. Use the query type "Overwrite" and then try again

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .