Emanuele De Sanctis
11/28/2025, 2:11 PMcannot insert multiple commands into a prepared statementkapa.ai
11/28/2025, 2:11 PMkapa.ai
11/28/2025, 2:11 PMyaml vars: insert_rows_method: chunk dbt_artifacts_chunk_size: 5000 This makes Elementary insert artifacts in smaller batches instead of one big statement, which has fixed Snowflake “too many expressions” errors and similar issues in post‑hooks. [[Snowflake list limit](https://elementary-community.slack.com/archives/C02CTC89LAX/p1699519549117769); [Too many queries](https://github.com/elementary-data/elementary/issues/1689)] If the failing part is specifically dbt columns upload, you can temporarily disable it: yaml vars: disable_dbt_columns_autoupload: true This was used as a hotfix for dbt_columns insert failures in Snowflake. [[Snowflake columns bug](https://elementary-community.slack.com/archives/C02CTC89LAX/p1708091691731959)] 2. If it’s concurrency / multiple jobs finishing together When multiple dbt runs finish at the same time, concurrent Elementary post‑hooks can conflict (especially on BigQuery and Redshift), causing transaction‑related errors. The documented mitigations are: - Disable automatic artifacts upload in hooks and run it separately on a schedule: yaml vars: disable_dbt_artifacts_autoupload: true Then update artifacts with: bash dbt run --select elementary.edr.dbt_artifacts at a controlled time, rather than on every job completion. [[BQ concurrent updates](https://elementary-community.slack.com/archives/C02CTC89LAX/p1692802428509179); [BQ DML rate limits](https://elementary-community.slack.com/archives/C02CTC89LAX/p1747726633866209)] - Or fully decouple running your project from updating Elementary tables: yaml models: your_project: +materialized: table elementary: +schema: elementary edr: +enabled: "{{ var('enable_elementary_models', false) }}" Then: bash dbt run # runs your models only dbt run --select elementary --vars '{enable_elementary_models: true}' so the Elementary models (and their writes) run in a separate, non‑overlapping job. [[Parallel jobs guidance](https://elementary-community.slack.com/archives/C02CTC89LAX/p1738245835314909)] 3. Version / schema mismatches after upgrade If this started right after upgrading Elementary, it may be hitting an object that is a view instead of a table (e.g., `INSERT statement's target must be a table`/“cannot insert into a view”). Users fixed this by: - Running: bash dbt run -s elementary after upgrading, to rebuild Elementary’s schema objects as the correct materializations. [[Redshift view insert issue](https://elementary-community.slack.com/archives/C02CTC89LAX/p1703064322575999); [Snowflake DBT_COLUMNS table](https://elementary-community.slack.com/archives/C02CTC89LAX/p1699528965324569)] --- What I’d recommend next 1. Check your dbt.log for the exact SQL Elementary is running when this error appears and which table it’s writing to. 2. Apply, in order: - insert_rows_method: chunk + dbt_artifacts_chunk_size. - If it points to dbt_columns, set disable_dbt_columns_autoupload: true. - If you run many jobs in parallel, consider disable_dbt_artifacts_autoupload: true and/or the pattern where Elementary models run in a separate job. If you can share (sanitized) warehouse type, Elementary version, and the failing SQL statement, I can narrow down which of these configs is most likely to fix your specific error.Emanuele De Sanctis
11/28/2025, 2:19 PMredshift-connector inability to process multiple commands in a prepared statement. the query that's failing is:
begin transaction;
insert into "dwh"."prod_elementary"."dbt_models" select * from "dbt_models__tmp_20251128134011060060134011118634";
commit;kapa.ai
11/28/2025, 2:19 PMkapa.ai
11/28/2025, 2:19 PMredshift-connector rejecting multiple SQL commands in a single prepared statement (begin; ... insert ...; commit;) rather than anything Elementary‑specific. From the knowledge sources, there are a few Redshift + Elementary post‑hook issues, but none explicitly mention this exact cannot insert multiple commands into a prepared statement error. We do, however, see: - Redshift regressions in dbt-redshift 1.5.x and later that break queries due to connector behavior, fixed or mitigated by dbt configuration changes. [[Redshift % regression](https://elementary-community.slack.com/archives/C02CTC89LAX/p1685633764828849)] - A more recent Redshift issue where Elementary’s on‑run‑end hooks started failing after upgrading `dbt-redshift`/dbt Cloud “Versionless”, and users fixed it by changing a dbt global flag rather than modifying Elementary. [[On-run-end commit error](https://github.com/elementary-data/elementary/issues/1712)] In that last case, the solution was: yaml # dbt_project.yml flags: restrict_direct_pg_catalog_access: False Users reported that enabling restrict_direct_pg_catalog_access in newer dbt-redshift versions caused Elementary’s hooks to fail, and setting it back to False restored normal behavior. [[On-run-end commit error](https://github.com/elementary-data/elementary/issues/1712)] Given that: - Your failing statement is a standard dbt transaction block (begin; insert; commit;) emitted by Elementary’s macro, and - The connector is the one refusing multiple commands, the most consistent, documented workaround in our sources is to adjust dbt’s Redshift flags rather than change Elementary SQL. ### Recommended next steps 1. In dbt_project.yml, add (or ensure) this config: yaml flags: restrict_direct_pg_catalog_access: False Then re‑run your dbt job and see if the Elementary post‑hook still fails. [[On-run-end commit error](https://github.com/elementary-data/elementary/issues/1712)] 2. If the error persists, based on the available docs I don’t have a confirmed Elementary‑side config that changes this begin/commit behavior specifically for Redshift. The knowledge sources don’t mention a Redshift‑only override of the transaction wrapper. Because of that, and since you’ve already traced it to redshift-connector, the strongest evidence we have is that this is a dbt/connector interaction, and the documented fix is the restrict_direct_pg_catalog_access flag. If that doesn’t resolve it, the next step would be to open an issue either: - in dbt-redshift (connector behavior with multi‑statement prepared queries), or - in Elementary’s repo with your exact dbt/dbt‑redshift versions and the failing SQL, so the teams can coordinate a connector‑friendly pattern for these transaction blocks.Euan Blackledge
12/01/2025, 10:11 AMDavid Baussart
12/01/2025, 11:45 AM/your_dbt_project/macros seems to have fixed the issue for me:
{% 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 %}
It's essentially a copy of athena__get_delete_and_insert_queries macro used by Elementary to insert into Redshift.
Instead of returning a string nested in a list (cf. default__get_delete_and_insert_queries), we make a list of strings. These macros are available in your project at your_dbt_project/dbt_packages/elementary/macros/utils/table_operations/delete_and_insert.sql
Ideally, Elementary's team should add this macro to delete_and_insert.sql (if they believe this is the proper fix)
Not sure why this started to get rejected by Redshift 🤷Euan Blackledge
12/01/2025, 11:46 AMSlackbot
12/01/2025, 11:46 AMDavid Baussart
12/01/2025, 11:47 AMEuan Blackledge
12/01/2025, 11:48 AMEuan Blackledge
12/01/2025, 11:55 AMNoya Offer
12/02/2025, 10:19 AMEuan Blackledge
12/02/2025, 10:34 AM0.18.0. We’ve not made any updates to the project beyond new/updated models over the last few months so have let the packages go a bit stale.Noya Offer
12/02/2025, 4:45 PMEuan Blackledge
12/02/2025, 4:56 PMDavid Baussart
12/02/2025, 5:06 PMBear Jordan
12/02/2025, 5:17 PMNoya Offer
12/07/2025, 12:51 PMMikhail Forde
12/08/2025, 7:59 PMMichael
12/09/2025, 3:16 AMdbt build commands it's fine, but the error persists when running dbt test commands 🤔Noya Offer
12/10/2025, 10:42 AMEric Williams
12/10/2025, 5:49 PMAayush Aggarwal
12/10/2025, 6:29 PMMichael
12/10/2025, 6:34 PMBear Jordan
12/10/2025, 7:36 PMNoya Offer
12/11/2025, 9:05 AMNoya Offer
12/11/2025, 9:05 AMNoya Offer
12/11/2025, 11:27 AMMichael
12/11/2025, 6:01 PMdbt test commands! no issue now kirby danceNoya Offer
12/16/2025, 1:08 PMEmanuele De Sanctis
03/19/2026, 11:31 AMsqlparse : https://github.com/andialbrecht/sqlparse/issues/826Emanuele De Sanctis
03/19/2026, 11:32 AM0.5.3 and the problem disappeared