Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data type to use so that 1 and 1.0 are both valid in Datomic?

{
  :db/id #db/id[:db.part/db]
  :db/ident :outcome/weighting
  :db/valueType :db.type/float
  :db/cardinality :db.cardinality/one
  :db.install/_attribute :db.part/db 
}

I get an error when I try and add 1 to the entity.

:message "java.lang.IllegalArgumentException: :db.error/wrong-type-for-attribute Value 1 is not a valid :float for attribute :outcome/weighting"

It works fine if I pass in 1.0.

I appreciate that (= (float? 1) false) but is there any other way I can avoid this via Datomic settings without parsing the incoming EDN and adjusting from 1 to 1.0?

like image 264
fatbatman Avatar asked Sep 26 '15 06:09

fatbatman


People also ask

What is job of Datalog query?

Datalog is a deductive query system, typically consisting of: A database of facts. A set of rules for deriving new facts from existing facts. a query processor that, given some partial specification of a fact or rule: finds all instances of that specification implied by the database and rules.

Is Datomic fast?

Because Datomic queries run in application process space, they can be faster than any possible RPC query in some circumstances.


1 Answers

You can't store both ints and floats in the same schema attribute in Datomic. So you'll need to coerce the value to whatever type you pick (probably float or double here) appropriately before transacting it. You can do this in the code performing the transaction, or could even do it in a transaction function.

like image 138
Alex Miller Avatar answered Nov 02 '22 23:11

Alex Miller