# I am trying to use dbt-athena-community in dbt core and while converting my merge into procedure to dbt syntax, getting this error: mismatched input 'inserts'. Expecting: '(', 'ALL', 'DISTINCT', 'SELECT', 'TABLE', 'VALUES'. Has anyone faced this issue ?

**URL:** <https://discourse.getdbt.com/t/i-am-trying-to-use-dbt-athena-community-in-dbt-core-and-while-converting-my-merge-into-procedure-to-dbt-syntax-getting-this-error-mismatched-input-inserts-expecting-all-distinct-select-table-values-has-anyone-faced-this-issue/10532>\
**Category:** Help\
**Created:** [October 27, 2023, 8:22am UTC](https://discourse.getdbt.com/t/i-am-trying-to-use-dbt-athena-community-in-dbt-core-and-while-converting-my-merge-into-procedure-to-dbt-syntax-getting-this-error-mismatched-input-inserts-expecting-all-distinct-select-table-values-has-anyone-faced-this-issue/10532 "2023-10-27T08:22:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![riniratnakar](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@riniratnakar](https://discourse.getdbt.com/u/riniratnakar)\
**Post date:** [October 27, 2023, 8:22am UTC](https://discourse.getdbt.com/t/i-am-trying-to-use-dbt-athena-community-in-dbt-core-and-while-converting-my-merge-into-procedure-to-dbt-syntax-getting-this-error-mismatched-input-inserts-expecting-all-distinct-select-table-values-has-anyone-faced-this-issue/10532/1 "2023-10-27T08:22:59Z")

</div>

I am trying to use dbt-athena-community in dbt core and while converting my merge into procedure to dbt syntax, getting this error: mismatched input ‘inserts’. Expecting: ‘(’, ‘ALL’, ‘DISTINCT’, ‘SELECT’, ‘TABLE’, ‘VALUES’.  
I am trying to convert my DML stored procedure to a dbt syntax having Update/Inserts

## What I’ve already tried

I have referred to this documentation and created my own model:

> **[Migrate from DDL, DML, and stored procedures | dbt Developer Hub](https://docs.getdbt.com/guides/migrate-from-stored-procedures)**
>
> Learn how to transform from a historical codebase of mixed DDL and DML statements to dbt models, including tips and patterns for the shift from a procedural to a declarative approach in defining datasets.

```auto
WITH
using_clause AS (
SELECT merchant_id, corporate_id, merchant_name, xls_terminalid_count, addr, last_update_by, last_update_date, status, merchant_no, geo_coord, lat, lon, marketing_desc, referencelogo, loyaltypartnerprogramid, loyaltypartnerprogramname, merchantprogramdescription, cpg_sub_forbid, is_active_for_redemption, extracted_date,cast(current_timestamp as timestamp(6)) as insert_date,file_name,cast(current_timestamp as timestamp(6)) as load_timestamp
from (
	select * , ROW_NUMBER () over (partition by merchant_id order by extracted_date desc) rn
	FROM xls_delta.merchant
) a where a.rn = 1
  {% if is_incremental() %}
        and load_timestamp > (SELECT max(load_timestamp) FROM {{ this }})
    {% endif %}
),
updates AS (
SELECT
      corporate_id, merchant_name, xls_terminalid_count, addr, last_update_by, cast(last_update_date as timestamp(6)) last_update_date, status, merchant_no, geo_coord, lat, lon, marketing_desc, referencelogo, loyaltypartnerprogramid, loyaltypartnerprogramname, merchantprogramdescription, cpg_sub_forbid, is_active_for_redemption, extracted_date,cast(current_timestamp as timestamp(6)) as insert_date,file_name,load_timestamp
  FROM using_clause
  {% if is_incremental() %}
        WHERE merchant_id IN (SELECT merchant_id FROM {{ this }})
    {% endif %}
),
inserts AS (
  SELECT
  merchant_id,corporate_id, merchant_name, xls_terminalid_count, addr, last_update_by, cast(last_update_date as timestamp(6)) last_update_date, status, merchant_no, geo_coord, lat, lon, marketing_desc, referencelogo, loyaltypartnerprogramid, loyaltypartnerprogramname, merchantprogramdescription, cpg_sub_forbid, is_active_for_redemption, extracted_date,cast(current_timestamp as timestamp(6)) as insert_date,file_name,load_timestamp
    FROM using_clause
      WHERE merchant_id NOT IN (SELECT merchant_id FROM updates)
)
SELECT * FROM updates UNION inserts

```

The error I am getting:  
Failed to execute query.  
dbt | Traceback (most recent call last):  
dbt | File “/usr/local/lib/python3.10/site-packages/pyathena/common.py”, line 522, in \_execute  
dbt | query\_id = retry\_api\_call(  
dbt | File “/usr/local/lib/python3.10/site-packages/pyathena/util.py”, line 85, in retry\_api\_call  
dbt | return retry(func, \*args, \*\*kwargs)  
dbt | File “/usr/local/lib/python3.10/site-packages/tenacity/ **init**.py”, line 379, in **call**  
dbt | do = self.iter(retry\_state=retry\_state)  
dbt | File “/usr/local/lib/python3.10/site-packages/tenacity/ **init**.py”, line 314, in iter  
dbt | return fut.result()  
dbt | File “/usr/local/lib/python3.10/concurrent/futures/\_base.py”, line 451, in result  
dbt | return self.\_\_get\_result()  
dbt | File “/usr/local/lib/python3.10/concurrent/futures/\_base.py”, line 403, in \_\_get\_result  
dbt | raise self.\_exception  
dbt | File “/usr/local/lib/python3.10/site-packages/tenacity/ **init**.py”, line 382, in **call**  
dbt | result = fn(\*args, \*\*kwargs)  
dbt | File “/usr/local/lib/python3.10/site-packages/botocore/client.py”, line 535, in \_api\_call  
dbt | return self.\_make\_api\_call(operation\_name, kwargs)  
dbt | File “/usr/local/lib/python3.10/site-packages/botocore/client.py”, line 980, in \_make\_api\_call  
dbt | raise error\_class(parsed\_response, operation\_name)  
dbt | botocore.errorfactory.InvalidRequestException: An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: line 47:29: mismatched input ‘inserts’. Expecting: ‘(’, ‘ALL’, ‘DISTINCT’, ‘SELECT’, ‘TABLE’, ‘VALUES’
