Parameterized queries

This post was last updated for 185 days ago, and the information may already be changed


I would like to be able to use an attribute of the parent block when writing an SQL query in an embed block. For the sake of example, consider I am in the document Trip to the Moon​ and I want to make a query that collects links to it. I would write

select b.* from blocks as b where b.content like "%trip to the moon%" order by updated desc

But I am already in Trip to the Moon​ (a document or a parent block with that name), so ideally I would like to grab the current document's title/name. I would like to replace the literal string "%trip to the moon%"​ with something like :parent.title​. How can I achieve this?

    Welcome to here!

    Here we can learn from each other how to use SiYuan, give feedback and suggestions, and build SiYuan together.

    Signup About
    Please input reply content ...
    • ciwoyipang 1

      SQLQuery 用法记录
      思源 SQL 新人指南 SQL 语法 Query 模板

      The attachment is the exported original text, which can be directly imported.

      Then use the browser opening function of Siyuan to use translation tools

    • MiscReply
    • alvorithm
      VIP Warrior Author

      Dear @ciwoyipang, thank you so much for making me aware of the query widget. It is a very featureful extension. But I think I did not describe my need clearly. What I am after is that the query block asks its parent for the text "trip to the moon", i.e. that string in the query should be generated automatically from the context.

      select * from blocks as b where b.content like "%insert here the title or the name of the parent block%"

      So if I put this query inside a document named "The mother of all queries" it would automatically fill in the value and execute

      select * from blocks as b where b.content like "%The mother of all queries%"

      Do you have an idea on how to customize queries based on the context of the query block (e.g. the parent, or the preceding block)?


      PS. in order to have the type column values translated, is it necessary to do it in Siyuan or in the widget code?

    • ciwoyipang

      In addition, the embedding blocks of the ontology support JS.You can use plugins to enhance embedded block queries.



    • ciwoyipang

      思源 SQL 新人指南:SQL 语法 + Query + 模板 - 链滴 (

      SQL&Query 用法记录 - 链滴 (

      The above are two high-quality introductory articles from the Chinese community, which you may find readable using a translation tool.

      1 Reply
    • Visit all replies