# Strange behavior when transacting historical data

**URL:** <https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485>\
**Category:** Troubleshooting\
**Created:** [October 22, 2024, 11:26am UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485 "2024-10-22T11:26:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikhail](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/mikhail/32/620_2.png) [@Mikhail](https://forum.datomic.com/u/Mikhail)\
**Post date:** [October 22, 2024, 11:26am UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485/1 "2024-10-22T11:26:33Z")

</div>

I am trying to transact historical data from a Postgres database, and stumbled upon this strange case. Here’s the minimal example:

```auto
  (def uri (str "datomic:mem://" (str (gensym "mem-db-"))))

  (def schema
    [{:db/id "datomic.tx"
       :db/txInstant #inst "2017-01-01"}
      {:db/ident :user/id
       :db/valueType :db.type/long
       :db/cardinality :db.cardinality/one
       :db/unique :db.unique/identity}])

  (def data
    [
     [{:db/id "datomic.tx"
       :db/txInstant #inst "2018-09-21T20:40:33.985606000-00:00"}
      {:user/id 1}]
     [{:db/id "datomic.tx"
       :db/txInstant #inst "2018-10-21T20:40:33.985606000-00:00"}
      {:user/id 2}]])

  (d/create-database uri)

  (def conn (d/connect uri))

  @(d/transact conn schema)

  (doseq [d data]
    @(d/transact conn d))

```

Results in

```auto
Execution error (Exceptions$IllegalArgumentExceptionInfo) at datomic.error/arg (error.clj:79).
  :db.error/past-tx-instant Time conflict: Fri Sep 21 21:40:33 WEST 2018 is older than database basis

```

---

<div class="post-metadata">

**Author:** ![Mikhail](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/mikhail/32/620_2.png) [@Mikhail](https://forum.datomic.com/u/Mikhail)\
**Post date:** [October 22, 2024, 12:08pm UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485/2 "2024-10-22T12:08:54Z")

</div>

This behavior has to do with the type of instant used. In my data I had java.sql.Timestamp, and changing that to java.util.Date fixed things.

---

<div class="post-metadata">

**Author:** ![Mikhail](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/mikhail/32/620_2.png) [@Mikhail](https://forum.datomic.com/u/Mikhail)\
**Post date:** [October 22, 2024, 3:38pm UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485/3 "2024-10-22T15:38:53Z")

</div>

But the funny part is that even though I managed to transact my data by converting to Date, the minimal example above still breaks — and I don’t see why.

---

<div class="post-metadata">

**Author:** ![mharris](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mharris](https://forum.datomic.com/u/mharris)\
**Post date:** [October 24, 2024, 12:27pm UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485/4 "2024-10-24T12:27:22Z")

</div>

Datomic will allow you to transact historical data by overriding the `:db/txInstant` on the transaction. However, it will allow this only as long as each new datom is later than `:db/txInstant` on the last datom transacted. If you don’t do that, you’ll get this error. So take a look at the very last tx you’ve transacted, and you’ll be locked out of transacting anything before that time.

---

<div class="post-metadata">

**Author:** ![Mikhail](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/mikhail/32/620_2.png) [@Mikhail](https://forum.datomic.com/u/Mikhail)\
**Post date:** [October 26, 2024, 11:55am UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485/5 "2024-10-26T11:55:28Z")

</div>

Thanks, I’m quite aware of that. If you take a look at the code example you can see, that all txInstants are sorted chronologically, and the error still persists.

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [October 29, 2024, 9:21am UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485/6 "2024-10-29T09:21:47Z")

</div>

> [@Mikhail](#):
>
> ```auto
> (d/create-database uri)
> 
> (def conn (d/connect uri))
> 
> @(d/transact conn schema)
> 
> (doseq [d data]
> @(d/transact conn d))
> 
> ```

I had success using your example, I used the newest datomic

Try:

```auto
   [
    [{:db/id "datomic.tx"
      :db/txInstant #inst "2018-09-21T20:40:33.985606000-00:00"}
     {:user/id 1}
     {:user/id 2}]
   ])
```

---

<div class="post-metadata">

**Author:** ![Mikhail](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/mikhail/32/620_2.png) [@Mikhail](https://forum.datomic.com/u/Mikhail)\
**Post date:** [October 29, 2024, 10:10pm UTC](https://forum.datomic.com/t/strange-behavior-when-transacting-historical-data/2485/7 "2024-10-29T22:10:33Z")

</div>

You are right, it does work in the latest version. I had 1.0.7075. Thanks!
