Iterate through distinct column value in DBT with Jinja

I’m new to dbt and Jinja and currently working on a project where I need to iterate through distinct ID values, filter a table based on each ID, and then either materialize the result as a separate table or export it as a CSV file to S3. What I tried is:

{% set get_id_query %}
  select distinct id from  table_name limit 10
{% endset %}
{% set results = run_query(get_id_query) %}
{% if execute %}
 {# Return the first column #}
 {% set results_list = results.columns[0].values() %}
 {% else %}
 {% set results_list =[]%}
{% endif %}

{% for id in results_list %}
 select * from table_name
  WHERE id = '{{ id }}'
 limit 1 
{% endfor %}

I am trying to insert config within for loop like

{{ '{{' }} config(
    materialized='table',
      unique_id='result_{{id}}'
{{ '}}' }}
 select * from table_name 
  WHERE id = '{{ id }}'
 limit 1 
{% endfor %}

but its not working as expected though I managed to get the separate config for each id. Can someone guide on how to create multiple table using jinja output?