You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Snowflake关联更新SQL报错'missing SET at FROM'问题排查求助

Solution

To resolve the syntax error, you need to use Spark SQL's MERGE INTO syntax instead of Snowflake's UPDATE ... FROM approach, since spark.sql() uses Spark's SQL dialect (not Snowflake's native syntax).

Replace your update query with this:

MERGE INTO FINAL_TBL x
USING STG_TBL y
ON y.customer_id = x.customer_id AND y.end_date = x.end_date
WHEN MATCHED THEN UPDATE SET x.NAME = y.NAME

Why the Original Query Failed

Spark SQL does not support the Snowflake-specific UPDATE ... FROM syntax. Your initial attempt to replace FROM with USING still kept the UPDATE keyword, which is invalid in Spark for join-based updates.

MERGE INTO is the standard Spark SQL construct for performing updates (and inserts/deletes) based on a join between two tables, aligning with both Spark's syntax and Snowflake's supported operations when using the Spark connector.

Alternative: Execute Snowflake Native Syntax Directly

If you prefer to use Snowflake's original UPDATE ... FROM syntax, you can execute it directly via the Snowflake Python connector (bypassing Spark SQL):

import snowflake.connector

# Establish connection
conn = snowflake.connector.connect(
    user='your_user',
    password='your_password',
    account='your_account',
    warehouse='your_warehouse',
    database='your_db',
    schema='your_schema'
)

# Execute the query
cursor = conn.cursor()
update = """
UPDATE FINAL_TBL x
FROM STG_TBL y
SET x.NAME = y.NAME
WHERE y.customer_id = x.customer_id AND y.end_date = x.end_date
"""
cursor.execute(update)
conn.commit()

# Close connections
cursor.close()
conn.close()

This approach runs the query directly on Snowflake's engine instead of processing it through Spark.

内容的提问来源于stack exchange,提问作者Rigori67

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 19:30:32