<@U088WCP3B4P> Encountered an error similar to thi...
# ask-elementary-ai
k
@kapa.ai Encountered an error similar to this thread. im getting run failures on dbt_elementary.dbt_models and dbt_elementary.dbt_columns. im on redshift as well and the error is:
Copy code
09:37:16    Database Error in model dbt_columns (models/edr/dbt_artifacts/dbt_columns.sql)
  cannot insert multiple commands into a prepared statement
  compiled code at target/run/elementary/models/edr/dbt_artifacts/dbt_columns.sql
09:37:16  
09:37:16
09:37:16    compiled code at target/compiled/elementary/models/edr/dbt_artifacts/dbt_columns.sql
09:37:16  
09:37:16
09:37:16  Failure in model dbt_models (models/edr/dbt_artifacts/dbt_models.sql)
09:37:16
09:37:16    Database Error in model dbt_models (models/edr/dbt_artifacts/dbt_models.sql)
  cannot insert multiple commands into a prepared statement
  compiled code at target/run/elementary/models/edr/dbt_artifacts/dbt_models.sql
k
A message from kapa.ai
You’re hitting a known Redshift issue with Elementary’s
on-run-end
artifacts upload: Redshift (or the
redshift-connector
) rejects a single prepared statement that contains multiple commands (
begin; ... insert ...; commit;
), which is how the current
delete_and_insert
logic is compiled for Redshift. [[Slack thread](https://elementary-community.slack.com/archives/C08HW57FGN9/p1764339093392769); [GitHub issue](https://github.com/elementary-data/elementary/issues/2063)] ### Short‑term workarounds 1. Disable automatic artifacts upload in
on-run-end
In `dbt_project.yml`:
Copy code
yaml    vars:      elementary:        disable_dbt_artifacts_autoupload: true        disable_run_results: true        disable_dbt_invocation_autoupload: true
This stops the failing
dbt_models
/
dbt_columns
uploads during
on-run-end
. You can then follow the docs to upload artifacts in a separate run instead of via hooks. [[GitHub issue](https://github.com/elementary-data/elementary/issues/2063)] 2. Temporarily disable Elementary entirely on problematic targets Example:
Copy code
yaml    models:      elementary:        +schema: elementary        enabled: "{{ target.name in ['beta'] }}"
This was used by others to keep prod stable while debugging. [[GitHub issue](https://github.com/elementary-data/elementary/issues/2063)] 3. Macro override workaround (project‑level macro) One community member fixed it by overriding the Redshift implementation of
get_delete_and_insert_queries
so that it returns separate statements instead of a single multi‑command statement. [[Slack thread](https://elementary-community.slack.com/archives/C08HW57FGN9/p1764339093392769)] Create
macros/redshift_get_delete_and_insert_queries.sql
in your dbt project:
Copy code
sql    {% macro redshift__get_delete_and_insert_queries(relation, insert_relation, delete_relation, delete_column_key) %}        {% set queries = [] %}         {% if delete_relation %}            {% set delete_query %}                delete from {{ relation }}                where                {{ delete_column_key }} is null                or {{ delete_column_key }} in (select {{ delete_column_key }} from {{ delete_relation }});            {% endset %}            {% do queries.append(delete_query) %}        {% endif %}         {% if insert_relation %}            {% set insert_query %}                insert into {{ relation }} select * from {{ insert_relation }};            {% endset %}            {% do queries.append(insert_query) %}        {% endif %}         {% do return(queries) %}    {% endmacro %}
This mirrors the community workaround and avoids
begin/commit
wrapping in a single prepared statement. [[Slack thread](https://elementary-community.slack.com/archives/C08HW57FGN9/p1764339093392769)] ### Status of an official fix The Elementary team acknowledged this Redshift issue and implemented a fix in the dbt package (PR
dbt-data-reliability#899
), with a note that it would be released “in a couple of days.” [[Slack thread](https://elementary-community.slack.com/archives/C08HW57FGN9/p1764339093392769); [GitHub issue](https://github.com/elementary-data/elementary/issues/2063)] However, the knowledge sources do not state clearly which released package version contains that fix, nor whether it’s backported to older versions. If you share your exact
elementary
dbt package version, you can: - Try upgrading to the latest available Elementary dbt package, or - Use the macro override +
disable_*_autoupload
vars above as a safe interim solution. If you’d like, paste your
packages.yml
and
vars: elementary:
section and I can suggest the minimal config change for your setup.
f
@kapa.ai it's solved this issue for redshift?
k
A message from kapa.ai
New message text here
j
Hello ! when using elementary version 0.21.0, i still face the issue when running tests
Copy code
<http://logging_config.logger.info|logging_config.logger.info>(f"COMMAND TEST BEFORE RUN: dbt {' '.join(cli_args_test_before)}")
response_test_before = dbt.invoke(cli_args_test_before)

# Add a small delay to allow Elementary background processes to complete
<http://logging_config.logger.info|logging_config.logger.info>("Waiting for Elementary metadata processing...")
time.sleep(5)

<http://logging_config.logger.info|logging_config.logger.info>(f"COMMAND TEST ON SEEDS: dbt {' '.join(cli_args_test_seeds)}")
response_test_seeds = dbt.invoke(cli_args_test_seeds)
Elementary: Runtime data: {"config": {"disable_run_results": true, "disable_dbt_artifacts_autoupload": true, "disable_dbt_invocation_autoupload": true}, "dbt_version": "1.9.10",
"elementary_version": "0.21.0"
, "database": "acm", "schema": "acm_elementary"} on redshift