# Error when running dbt run-operations with stage\_external\_sources macro. Ending up with sytax error, sql erro. Can someone help me with this ?

**URL:** <https://discourse.getdbt.com/t/error-when-running-dbt-run-operations-with-stage-external-sources-macro-ending-up-with-sytax-error-sql-erro-can-someone-help-me-with-this/20061>\
**Category:** Help\
**Created:** [August 8, 2025, 3:24pm UTC](https://discourse.getdbt.com/t/error-when-running-dbt-run-operations-with-stage-external-sources-macro-ending-up-with-sytax-error-sql-erro-can-someone-help-me-with-this/20061 "2025-08-08T15:24:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sachin](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sachin](https://discourse.getdbt.com/u/Sachin)\
**Post date:** [August 8, 2025, 3:24pm UTC](https://discourse.getdbt.com/t/error-when-running-dbt-run-operations-with-stage-external-sources-macro-ending-up-with-sytax-error-sql-erro-can-someone-help-me-with-this/20061/1 "2025-08-08T15:24:39Z")

</div>

```auto
dma_load = nonpiiDBTOperatorLoad(
    task_id = "dma_load",
    #bash_command = "dbt run-operation stage_external_sources --args 'select: Roundel_DMA.S3_ROUNDEL_DMA_WEEKLY' --vars 'ext_full_refresh: true' --target load_nonpii",
    bash_command = """dbt run-operation stage_external_sources_custom \

```

–args=‘{“select”: “Roundel\_DMA.S3\_ROUNDEL\_DMA\_WEEKLY”}’  
–vars=‘{“ext\_full\_refresh”: true}’  
–target load\_nonpii --debug"“”,  
retries = 0  
)

[2025-08-08, 12:40:11 UTC] {subprocess.py:93} INFO - 12:40:11 On macro\_stage\_external\_sources\_custom: show objects in DEV\_CONS360NONPII\_LOAD.AWSS3\_RAW [2025-08-08, 12:40:11 UTC] {subprocess.py:93} INFO - limit 10000 [2025-08-08, 12:40:11 UTC] {subprocess.py:93} INFO - [2025-08-08, 12:40:11 UTC] {subprocess.py:93} INFO - /\* {“app”: “dbt”, “dbt\_version”: “1.10.7”, “profile\_name”: “elementary”, “target\_name”: “load\_nonpii”, “connection\_name”: “macro\_stage\_external\_sources\_custom”} \*/; [2025-08-08, 12:40:11 UTC] {subprocess.py:93} INFO - 12:40:11 Opening a new connection, currently in state init [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - 12:40:12 SQL status: SUCCESS 250 in 0.930 seconds **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO -** 12:40:12 While listing relations in database=DEV\_CONS360NONPII\_LOAD, schema=AWSS3\_RAW, found: BRZMT\_LATITUDE\_LONGITUDE, “macro\_stage\_external\_sources\_custom”} \*/ [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - 12:40:12 Snowflake adapter: Snowflake query id: 01be3b78-0a0b-a45a-0002-a656a0fe75ca **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO -** 12:40:12 Snowflake adapter: Snowflake error: 001003 (42000): SQL compilation error: **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - syntax error line 2 at position 163 unexpected ‘’.** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO -** 12:40:12 Snowflake adapter: Error running SQL: macro stage\_external\_sources\_custom [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - 12:40:12 Snowflake adapter: Rolling back transaction. [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - 12:40:12 On macro\_stage\_external\_sources\_custom: Close **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO -** 12:40:12 Encountered an error while running operation: Database Error **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - 001003 (42000): SQL compilation error:** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - syntax error line 2 at position 163 unexpected ‘’.** [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - 12:40:12 Traceback (most recent call last): **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - File “/tmp/venv/lib/python3.12/site-packages/dbt/adapters/snowflake/connections.py”, line 320, in exception\_handler** [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - yield [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - File “/tmp/venv/lib/python3.12/site-packages/dbt/adapters/sql/connections.py”, line 148, in add\_query [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - \_execute\_query\_with\_retry( [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - File “/tmp/venv/lib/python3.12/site-packages/dbt/adapters/sql/connections.py”, line 97, in \_execute\_query\_with\_retry [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - cursor.execute(sql, bindings) [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - File “/tmp/venv/lib/python3.12/site-packages/snowflake/connector/cursor.py”, line 1137, in execute **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - Error.errorhandler\_wrapper(self.connection, self, error\_class, errvalue)** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - File “/tmp/venv/lib/python3.12/site-packages/snowflake/connector/errors.py”, line 279, in errorhandler\_wrapper** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - handed\_over = Error.hand\_to\_other\_handler(** [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - File “/tmp/venv/lib/python3.12/site-packages/snowflake/connector/errors.py”, line 334, in hand\_to\_other\_handler** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - cursor.errorhandler(connection, cursor, error\_class, error\_value)** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - File “/tmp/venv/lib/python3.12/site-packages/snowflake/connector/errors.py”, line 210, in default\_errorhandler** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - raise error\_class(** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - snowflake.connector.errors.ProgrammingError: 001003 (42000): SQL compilation error:** **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - syntax error line 2 at position 163 unexpected ‘’.** [2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - **[2025-08-08, 12:40:12 UTC] {subprocess.py:93} INFO - During handling of the above exception, another exception occurred:**

## 

```auto

```

---

<div class="post-metadata">

**Author:** ![Sachin](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sachin](https://discourse.getdbt.com/u/Sachin)\
**Post date:** [August 12, 2025, 1:12pm UTC](https://discourse.getdbt.com/t/error-when-running-dbt-run-operations-with-stage-external-sources-macro-ending-up-with-sytax-error-sql-erro-can-someone-help-me-with-this/20061/2 "2025-08-12T13:12:30Z")

</div>

I fixed this myself, I was using --debug, actually `--compile`, `--debug`, or `--defer` flags that prevent full execution.

I removed this —debug from my operator and Bash command and its solved the issue.
