I have a dataframe which is converted to a Spark df in Azure Databricks, then a temporary view:
spark_df = spark.createDataFrame(df)
spark_df.createOrReplaceTempView("myTemp")
I use the following to insert columns to an existing table:
spark.sql(
f"""MERGE INTO prp_b901_group_work.test_cg_policies_multiple_delta AS m
USING temp_table AS s
ON m.id = s.id
WHEN MATCHED THEN INSERT (m.premium_usd, m.limit_usd) VALUES (s.premium_usd, s.limit_usd)"""
)
So basically the intention is to use the columns that originated from the spark_df
(s.colnew_1, s.colnew_2
) into the table x.y
(x - database; y - table). The two data sources match on the "id".
However, the error message is:
ParseException:
[PARSE_SYNTAX_ERROR] Syntax error at or near 'INSERT'(line 4, pos 18)
Where is this going wrong?