noted
June 27, 2024, 4:42pm
1
In this thread , the following query is used to match blocks that are tagged #inbox
:
#+BEGIN_QUERY
{:title [:h6 "Blocks tagged #inbox"]
:query [:find (pull ?h [*])
:in $ ?target
:where
[?p :block/name ?target]
[?h :block/refs ?p]]
:inputs ["inbox"]
:table-view? false}
#+END_QUERY
However, the above query does not find blocks like this:
- #inbox
- hello world
Instead, this simple query finds all blocks referring #inbox
, including hello world
above:
#+BEGIN_QUERY
{ :query [[inbox]] }
#+END_QUERY
How do I write an advanced query that returns the same results as the :query
block above?
Not sure what :query ([[inbox]])
is suppose to be honestly.
But for both simple and your posted advanced query the block - #inbox
is returned.
- hello world
is a child of - #inbox
and is therefore also shown as well.
1 Like
noted
June 27, 2024, 6:12pm
3
Fixed the simple query above.
Thank you for the response, that’s helpful. And you’re right, indeed, that block gets returned, which I hadn’t noticed.
But that makes me realize I oversimplified my question. This query gives me a list of all the TODO blocks tagged with #inbox
:
#+BEGIN_QUERY
:query (and (task TODO) [[inbox]])
#+END_QUERY
However, I want to further filter this and only display the TODO blocks that 1) have a schedule associated with them, and 2) are scheduled for today or earlier.
I’m finding no way to do this with :query
. When I used the advanced query below instead:
#+BEGIN_QUERY
{ :query [:find (pull ?b [* {:block/_parent ...}])
:in $ ?date ?tag
:where [?b :block/scheduled ?day]
[(<= ?day ?date)]
[?p :block/name ?tag]
[?b :block/refs ?p]
[?b :block/marker ?marker]
[(contains? #{"TODO"} ?marker)]
[?b :block/content ?desc]]
:inputs [:today "inbox"]
}
#+END_QUERY
…it leaves out the block I mentioned above (where the TODO block is a child of the #inbox
tag).
EDIT: Addressed in SCHEDULED tasks with a tag in the parent
1 Like