Blocks having certain properties

Hi,

I’m new to queries and especially advanced queries. I’m trying to create a query that fetches all block that

  1. has an “item-type” property with value “X”
  2. AND has a “source” property that starts with “Y”
  3. AND doesn’t have a property named “template”

I have created the query below by copy/pasting stuff from all over the documentation and the support forum, but I get the error "Missing rules var '%' in :in" . Would appreciate some help with it. I didn’t include the third criteria in the below snippet since I’m stuck at the second step. But, please include that in your response if you can.

#+BEGIN_QUERY
{
  :title "I'm stuck"
  :query [
    :find (pull ?b [*])
    :where
    [?b :block/properties ?props]
    [(get ?props :item-type) ?it]
    [(get ?props :source) ?source]
    [(str ?source) ?str-source]
    (and
        [(= ?it #{"X"})]
        [(clojure.string/starts-with? ?str-source "Y")]
    )
  ]
}
#+END_QUERY

Welcome.

  • Blind pasting (or even LLM-prompting) rarely works with such queries.
  • Top-level :where is already an implicit (and )
  • Try something like this:
    #+BEGIN_QUERY
    {
      :query [:find (pull ?b [*])
        :where
            [?b :block/properties ?props]
            [(get ?props :item-type) ?it]
            [(get ?props :source) ?source]
            [(str ?source) ?str-source]
            [(= ?it #{"X"})]
            [(clojure.string/starts-with? ?str-source "Y")]
            (not [(get ?props :template)] )
      ]
    }
    #+END_QUERY
    

Thank you! I thought I tried that combination, but apparently not. That returns the expected result.