Journal to-do's (very simple, but its my first query, so I have some error)

Hi,
this is the first time I’m trying a query but I am not getting the results I need… yet :slight_smile:

What I want to do:
have a template for my journal where there is a query that picks up on all the to-do’s that weren’t done on the previous journal page.

first question: is there a variable that targets the previous existing journal page? if not, I would just qo with 3days ago, so that it also works on a Monday

second question: how would the query look like? I have searched around and pieced together this query

#+BEGIN_QUERY
{
  :title "Journal Tasks"
  :query [
    :find (pull ?h [*])
    :in $ ?start ?today
    :where
      [?h :block/marker ?marker]
      [?h :block/page ?p]
      [?p :page/journal? true]
      [(contains? #{"LATER" "NOW" "TODO" "DOING"} ?marker)]
  ]
  :inputs [:10d-before :today ]
  :collapsed? false
}
#+END_QUERY

This is not yet complete but the functionality of getting to-do’s from journal page is working.

So the part that I’m struggling with is adding the time-range. I tried adding these two lines:

      [(>= ?p ?start)]
      [(<= ?p ?today)]

which makes my query look like this:

#+BEGIN_QUERY
{
  :title "Journal Tasks"
  :query [
    :find (pull ?h [*])
    :in $ ?start ?today
    :where
      [?h :block/marker ?marker]
      [?h :block/page ?p]
      [?p :page/journal? true]
      [(>= ?p ?start)]
      [(<= ?p ?today)]
      [(contains? #{"LATER" "NOW" "TODO" "DOING"} ?marker)]
  ]
  :inputs [:10d-before :today]
  :collapsed? false
}
#+END_QUERY

But then it returns “No matched results”.

Can someone spot the error?

  • first question
    • No such variable.
      • It is still possible to calculate it within the query, but sounds like an overkill.
  • second question
    • The issue:
      • Things like :today and :10d-before return a date representation
        • something like 20250501
      • While things like :block/page ?p return an id representation
        • something like {:db/id 3210}
      • Dates and ids are not meaningfully comparable to each-other, therefore the query fails.
    • The fix:
      • replace these lines:
        [?p :page/journal? true]
        [(>= ?p ?start)]
        [(<= ?p ?today)]
        
      • with these ones:
        [?p :page/journal-day ?d]
        [(>= ?d ?start)]
        [(<= ?d ?today)]
        
    • The reason this works:
      • :page/journal-day ?d returns a date representation
        • This is comparable to the input dates.
      • :page/journal? is redundant
2 Likes

one more question: can you point me into the right direction when it comes to logseq query documentations? which is the best resource to check out? Where can I see what the properties are of each of these things

1 Like

Check these places:

3 Likes

I keep forgetting to ask about this thanks so much @metaloid. This is currently my favourite post.