# ERROR: A document with the same primary key exists already (SQLSTATE 23505)

**URL:** <https://community.cratedb.com/t/error-a-document-with-the-same-primary-key-exists-already-sqlstate-23505/1810>\
**Category:** CrateDB\
**Tags:** prometheus\
**Created:** [July 19, 2024, 1:25pm UTC](https://community.cratedb.com/t/error-a-document-with-the-same-primary-key-exists-already-sqlstate-23505/1810 "2024-07-19T13:25:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsgaah](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tsgaah](https://community.cratedb.com/u/tsgaah)\
**Post date:** [July 19, 2024, 1:25pm UTC](https://community.cratedb.com/t/error-a-document-with-the-same-primary-key-exists-already-sqlstate-23505/1810/1 "2024-07-19T13:25:51Z")

</div>

Using CrateDB with the adapter for Prometheus metric LTS. The table has been created as follows:

```sql
CREATE TABLE "metrics" (
    "timestamp" TIMESTAMP,
    "labels_hash" STRING,
    "labels" OBJECT(DYNAMIC),
    "value" DOUBLE,
    "valueRaw" LONG,
    "day__generated" TIMESTAMP GENERATED ALWAYS AS date_trunc('day', "timestamp"),
    PRIMARY KEY ("timestamp", "labels_hash", "day__generated")
  ) PARTITIONED BY ("day__generated")
WITH (codec = 'best_compression');

```

However, duplicate primary key errors are produced. What are we missing here? Looks like they should be unique.

---

<div class="post-metadata">

**Author:** ![hernanc](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/hernanc/32/676_2.png) [@hernanc](https://community.cratedb.com/u/hernanc)\
**Post date:** [July 31, 2024, 1:28pm UTC](https://community.cratedb.com/t/error-a-document-with-the-same-primary-key-exists-already-sqlstate-23505/1810/2 "2024-07-31T13:28:56Z")

</div>

Hi,  
Could you share what version of Prometheus you are running and how you configured the `remote_write`?

---

<div class="post-metadata">

**Author:** ![tsgaah](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tsgaah](https://community.cratedb.com/u/tsgaah)\
**Post date:** [August 1, 2024, 11:30am UTC](https://community.cratedb.com/t/error-a-document-with-the-same-primary-key-exists-already-sqlstate-23505/1810/3 "2024-08-01T11:30:08Z")

</div>

Hi, the versions are:

Prometheus - 2.36.2  
CrateDB Prometheus Adapter - 0.5.1  
CrateDB version - 5.7.1-1

Remote-write has been configured as:

remote\_write:

- url: [http://X.X.X.X:9268/write](http://X.X.X.X:9268/write)  
queue\_config:  
max\_samples\_per\_send: 1000  
max\_shards: 200  
capacity: 2500
