:as is ignored for :db/id in pull expressions

If to execute the next query:

(d/q '[:find
 [(pull ?User [[:db/id :as "id2"][:User/bigDec :as "bigDec2"]]) ...]
 :in
 $
 :where

 [?User :User/bigDec _]
]
(d/db conn))

then the result is:

[{:db/id 17592186045418, "bigDec2" 3.02M} {:db/id 17592186045421, "bigDec2" 3.020M} {:db/id 17592186045423, "bigDec2" 3.020M}]

We see that maps contain :db/id instead of “id2”, is it expected result or I’m doing something wrong? Thanks

3 Likes

Hi @nikolayandr, db/id is special, but I see how this is inconsistent behavior and we either need to adjust this behavior to allow for aliasing or specify in the docs that db/id can not be aliased. I need to discuss this issue with the team and confirm what the correct course here is. I’ll update you as we’ve had a chance to review.

2 Likes

I just needed this feature again today.

We are exposing our entity ids in denormalized Excel and Google Sheets spreadsheets and it would help the spreadsheet template developers, if they could see :account/eid - as in Entity ID - alongside with the :account/id, which is the accounting system’s own ID.

We would like to apply this convention system wide, so it would be really convenient, if we could take care of this declaratively.

That being said, it would also be nice, if we could pull an attribute both with their original name and with an alias, eg.

[:qb.account/id
 [:qb.account/id :as :account/id]]

which throws

Execution error (ExceptionInfo) at datomic.core.error/raise (error.clj:55).
:pull/duplicate-attribute Multiple specifications for :qb.account/id

currently.

Hi @jaret. Could you please tell me whether there is any decision on how :db/id might be treated(either need to adjust this behavior to allow for aliasing or specify in the docs that db/id can not be aliased) in pull expressions?