Advanced query to show all pages with status property

I’m trying to develop an advanced query that shows all pages with a value for the “status” property.

This is the simple query that works: {{query (page-property :status)}}

This is my attempt at the advanced query:

#+BEGIN_QUERY
{:title [:h3 "📊 Projects"]
 :query [:find (pull ?p [*])
         :where
   [?p :block/properties ?prop]
   [(get ?prop :status) ?status]
   [(= ?status "[[IN-PROGRESS]]")]
   [(= ?status "[[WAITING]]")]
   [(= ?status "[[LATER]]")]
   [(= ?status "[[BACKLOG]]")]
 ]
 :view (fn [result] (for [r result] [:div [:a.tag.mr-1 {:href (str "#/page/" (clojure.string/replace r "/" "%2F") )} r ] ] ) )
}
#+END_QUERY

Any help would be appreciated!

  • The simple query {{query (page-property :status)}} checks for the existence of page-property status:: , no matter its value.
  • In contrast, your advanced query:
    • initially makes the same check [(get ?prop :status) ?status]
    • but then also checks the value [(= ?status "...")]
    • and compares it against 4 different strings: "[[IN-PROGRESS]]", "[[WAITING]]", "[[LATER]]", "[[BACKLOG]]"
      • but it is impossible for a value to be equal to all four strings at the same time
  • What are you trying to do?
    • Maybe check if the value belongs to a set of the four strings?
      • If so, you need either:
        • an or-clause
        • an expression contains?

Thanks for clarifying. Ideally, I’d like to have an advanced query that shows all blocks with status as well as an advanced query for each status. I removed the lines to check for value and the value strings, and I get this error:

query-properties:: [:page :block]
#+BEGIN_QUERY
{:title [:h3 "📊 Projects"]
 :query [:find (pull ?p [*])
         :where
   [?p :block/properties ?prop]
   [(get ?prop :status) ?status]
 ]
 :view (fn [result] (for [r result] [:div [:a.tag.mr-1 {:href (str "#/page/" (clojure.string/replace r "/" "%2F") )} r ] ] ) )
}
#+END_QUERY

Your :view fails because it is fed blocks, while it expects strings.

  • Replace (pull ?p [*]) with a simple string variable, e.g. ?name
  • Read the string with a line, e.g. [?p :block/original-name ?name]

Thanks. I copied the view from another query, not realizing the mismatch, and I don’t need that view so I removed it.

For the query, I used this site to revise it: Logseq Query Builder

Example below. I have queries for each status, and just change out the title and final line.

Thanks for your help!

#+BEGIN_QUERY
{
:title [:h3 "🚧 Waiting"]
;; ---- Get every block into variable ?block
:query [:find (pull ?block [*])
;; ---- filter command
:where
;; ---- get page name (lowercase) from the special page block into variable ?pagename
[?block :block/name ?pagename]
;; ---- Select if block is a special page blockand has a single property (arg1) with value arg2
(page-property ?block :status "WAITING")
]
}
#+END_QUERY