Nested queries with the `q` function?

Is it possible to perform a nested query? Datomic docs says that it has a q function. Does DataScript have something similar? I tried :where [(q ‘[:find …]) ?result] but that gives me an “Unknown function 'q” error message.

My goal is to do something like the following:

#+BEGIN_QUERY
;; Find all incomplete tasks due the same day
;; as the journal page containing this query.
{
  :query [
    :find (pull ?b [*])
    :in $ ?journal-page
    :where
      [?b :block/marker ?marker]
      [(not= ?marker "DONE")]
      [(not= ?marker "CANCELED")]
      [(not= ?marker "CANCELLED")]
      [?b :block/deadline ?dl]
      [(q '[
        :find ?d
        :in $ ?journal-page
        :where
          [?p :block/name ?journal-page]
          [?p :block/journal? true]
          [?p :block/journal-day ?d]
      ] $ ?journal-page) [[?d]]]
      [(= ?dl ?d)]
  ]
  :inputs [:query-page]
}
#+END_QUERY

Perhaps there is an alternative way to accomplish this goal?

Welcome.

Most probably no, as I have never seen one.

Yes, normal queries can do everything nested queries could.

Maybe all you need in your case is quite simple:

...
[?b :block/deadline ?dl]
[?p :block/journal-day ?dl]
[?p :block/name ?journal-page]

Thank you! My original attempt to write the query (which was more complicated than the minimal one in my original post) failed because I misunderstood how or-join works. I thought that if a record matched multiple branches of the or then the first one listed would “win”. But it looks like an arbitrary winner is chosen (or maybe all combinations are returned? I’m still learning datalog), so I have to carefully craft each branch so that they are mutually exclusive. I misinterpreted the wrong results I was seeing as an issue fetching the :block/journal-day and thought I needed a subquery.

Thanks again!