Dynamically switch models between table and view

I am trying to dynamically switch between the materialization of table vs. view based on a select statement.
I have created a macro:

{% macro fetch_materialization_1() %}

  {% set materialization_type = run_query('SELECT "view"') %}
  {{ print("Materialization type found: " ~ materialization_type) }}
  {% set materialized = materialization_type[0][0]%}
  {{ materialized | trim }}
  
{% endmacro %}

And I am calling that macro using the following in my_model.sql:

{% set materialized = fetch_materialization_1()  %}

{{ config(materialized=materialized | trim) }}

When I am running my_model.sql I get the error message that no materialization is found. I believe that it has something to do with that materializations are determined during compile time and macros are not, but then it is strange that this macro is working (not using SQL inside of the macro):

{% macro fetch_materialization_1() %}

  {% set materialized = 'view' %}
  {{ print("Materialization type found: " ~ materialized) }}
  {{ materialized | trim }}

{% endmacro %}

Is there anyway to solve this using a SQL Statement?

Thanks a lot!

@neelie

dbt executes sql queries when its running in execute mode.
Materialisations are required when its building the manifest during this time dbt wont run sql queries on warehouse.

Hence its possible to get the materialization name from a sql query.