Fork me on GitHub

I’ve noticed that when I save a float e.g 200.9 then it is saved in the database (or at least displayed when I query the value) as 200.899993896484. Is that a feature and if so then why?


That is just how floats work. They cannot represent every decimal fraction precisely. Use bigdecimal type if you need exact decimal precision


ok, thanks. I guess for things like latitude/longitude, financial values etc. it would be wiser to use bigdecimal. For my simple use cases float has worked fine but the issue I have now is that each time I update an entity which has a float attribute then a change is triggered even if the value does not actually change (`200.9` provided vs 200.08999 in db). I would not mind it but I provide user with an activity log for each entity and now this float value change appears in every transaction. This was unexpected 😕


it's worth mentioning that financial data often works with (64-bit integer) millicents or microcents, to avoid exactly this kind of problem.


it means rounding, but no one cares if they win or lose a rounding to the thousandth of a penny.


i've faced problems with purchase amount in mysql because it was stored as float


For lat/long, I think floats are fine (assuming you aren't doing advanced GPS stuff). Just beware how much precision you actually want when displaying the numbers!


You have two options 1. use double as the name implies, has 2x the precision of float. 2. Recommended: save all your number in long format i.e 2009 and when you need to convert it you can always divide and get the value you desire. It also preserves the original value i.e no floating precision errors


Hi, I’m now to datomic and have run into a problem where it feels like there would be some kind of (at least semi-) best practice. I have a set of e of type foo in my database, and I want to filter with user input. foo has a few a that the user can include in their filter, including cases where you can filter by multiple enumerations of a specific a, but I’m struggeling to find a good way to do a conditional query. If I make a query that expects all possible as as :in, then (I think) it only matches when all the inputs are valid. I also sort of of feel like this is a place where I should use the pull api, but I have not found a way to run a pull over all e of foo.


Hope the explanation makes sense! I’m running datomic free on-prem, so I’ve not look at the client api.


Which number do you want: 1. "All e of type foo which have a1 OR a2 ?" 2. "All e of type foo which have a1 AND a2 ?"


2-ish. “All e of type foo which might have a1 AND a2 and a..n depending on user input”


@ your requirement is still ambiguous to me (what does "might have" mean?) but this may help:


That looks interesting, will check it out! In this concrete case, I have the e :cocktail that have a like :ingredient :title :author, the end-user should be albe to build a search query that can, but does not have to, include filtering by these


How many a exist ( or will exist? )


a known amount, all :cocktail have the same data in this set


Are you referring to a as an attribute for the entity?


yes, is that not correct? all cocktail enties have the same complete set of attributes


{:type :cocktails
 :cocktail "Martini"
 :ingredients ["Vodka", "vermouth"]
 :author "Unknown"}


And you want the ability to search for drinks which take Vodka


Yes! and that I can do, but the user should be able to search for cocktails that contain vodka, cream and have the word “russian” in fulltext


(d/q '[:find [(pull ?e [:cocktail/id :cocktail/title :cocktail/recipe :cocktail/preparation :cocktail/ingredients]) ...] :in $ [?ingredients ...] [?search ...] :where [?e :cocktail/ingredients ?ingredients] [(fulltext $ :cocktail/fulltext ?search) [[?e ?n]]]] (d/db conn) ingredients fulltext)


Start by building the query up as data using the cond-> macro. I cant help any more right now but I can later tonight.


is how far I got. its a concrete version of only qing two a, but it fails if any of the two vecs are empty, as it has nothing to match on


ah, cond->! I don’t think I’ve used that one before. thank you so much for all your help, will look into that!


When generating queries, it's usually more convenient to do it in map form:

{:find [...] :in [...] :where [...]}


oh, can you pass maps to q? that makes life a lot easier lol


For Datomic Cloud is it recommended to have one system per env? (dev, staging, prod) I ask bc the requires an app-name so not sure how to dynamically configure that based on environment. I found a related question in forum ( but no conclusive answer from anyone on it, so I’m wondering how people are handling different environments.


you can either have one or multiple systems you can configure your environments with ion environment maps and parameters


say I want multiple systems - so I’d keep the app/system name the same (but give them different environment maps? i didn’t think aws would allow multiple systems with same name but i’ll go ahead and try it


oh maybe the system name has to be different but the app-name can be the same (i guess that’s why that option exist)


that clarifies a lot, thanks


can i call d/with on the results of calling d/with ?


Yes, and a lot of power follows from that :)


right. i'm sure i've done this before, but i'm drawing a blank. d/with requires a d/with-db conn, but the result of d/with doesn't return a connection. does it?


oh of course. :db-after is already with-db'ed.


Does the peer uses connection pooling when using a SQL database?