I find Macros super helpful when writing SQL queries, especially with tables that have a wide range of values.
An example of a simple query I was writing in querybook was
SELECT
COUNT_IF(category_field IS NOT NULL AND category_field NOT IN ('"",' '0','[]', /*.... (other cases)*/) AS category_valid,
COUNT_IF(product_field IS NOT NULL AND product_field NOT IN ('"",' '0','[]', /*.... (other cases)*/) AS product_valid,
# More examples of the exact same pattern and a combination of the two fields.
FROM some.table;
It would have been super helpful to be able to have defined a macro like:
DEFINE MACRO is_arr_str return $1 IS NOT NULL AND $1 NOT IN ('"",' '0','[]', /*.... (other cases)*/);
SELECT
COUNT_IF({{ is_arr_str(category_field) }}) AS category_valid,
COUNT_IF({{ is_arr_str(product_field) }}) AS product_valid,
....
FROM some.table;
There's already some support for macros but within the source code only . However this requires commits to the repo and it's super flexible.
I worked with Claude Code to investigate options and came up with the following proposal to add cell level macros that are user defined and work with the Jinja templating engine. Adding that as an attachment here
2026-03-09-querybook-custom-macros-design.md
I find Macros super helpful when writing SQL queries, especially with tables that have a wide range of values.
An example of a simple query I was writing in querybook was
It would have been super helpful to be able to have defined a macro like:
There's already some support for macros but within the source code only . However this requires commits to the repo and it's super flexible.
I worked with Claude Code to investigate options and came up with the following proposal to add cell level macros that are user defined and work with the Jinja templating engine. Adding that as an attachment here
2026-03-09-querybook-custom-macros-design.md