datomic

Eva O 2025-04-09T13:13:47.415529Z

How would I do a transaction that works like SQL INSERT INTO foo VALUES (...) ON CONFLICT DO NOTHING ? I don't want to do an upsert. I want the first value in the database to win

2025-04-09T13:15:38.010089Z

> You can use nil for the old value to specify that the new value should be asserted only if no value currently exists.

2025-04-09T13:15:47.363979Z

I think is what you want

2025-04-09T13:15:56.242209Z

oh wait but you want "do nothing"

Eva O 2025-04-09T13:16:07.429889Z

What should the entity id be when I expect the entity to not be there?

2025-04-09T13:16:28.519009Z

nil works, but cas will throw

ghadi 2025-04-09T13:17:48.726369Z

just mark an attribute unique. transaction sends in an entity with a tempid

ghadi 2025-04-09T13:18:31.924099Z

no need for txfn. If you try to transact a novel entity with a value already associated with another entity, the transaction will be rejected.

2025-04-09T13:18:58.207619Z

unique by value you mean? that throws too (which, you can catch, but doesn't quite do what the sql does)

ghadi 2025-04-09T13:19:28.663819Z

any transaction that is aborted "throws" -- so what?

Eva O 2025-04-09T13:19:39.795229Z

It seems to do an upsert on the second insert if I just depend on the attribute being unique

Eva O 2025-04-09T13:19:55.329679Z

I want the second insert to do nothing

2025-04-09T13:20:14.742779Z

@eoogbe you gotta use unique by value (as opposed to unique by id)

ghadi 2025-04-09T13:20:18.022009Z

just paste what you typed, what the schema is, and what the result was.

2025-04-09T13:20:54.927309Z

you can make a txn fn that doesn't throw is my only additional contribution, but that may not be important to Eva.

Eva O 2025-04-09T13:23:48.737809Z

Can I use unique by value in lookup refs?

✔️ 1
2025-04-09T13:25:31.638249Z

https://docs.datomic.com/schema/identity.html#unique-values > Unique values have the same semantics as unique identities, with one critical difference: Attempts to assert a new tempid with a unique value already in the database will cause an IllegalStateException. It looks that way. I don't use them often, so I've not tested it myself.

Eva O 2025-04-09T13:26:12.157859Z

Ok great I will change it to use unique by value and catch the error

2
Eva O 2025-04-09T13:26:23.061279Z

Thanks