Hi Shambhu Rai ,
Thankyou for posting your query here.
I understand that your query is related to using SQL queries in Databricks to insert data into temporary tables.
We can't
insert data into the temporary table but we can mimic the insert with union all
(or) union
(to remove duplicates).
Example:
#create temp view
spark.sql("""create or replace temporary view temp_view_t as select 1 as no, 'aaa' as str""")
spark.sql("select * from temp_view_t").show()
#+---+---+
#| no|str|
#+---+---+
#| 1|aaa|
#+---+---+
#union all with the new data
spark.sql("""create or replace temporary view temp_view_t as select * from temp_view_t union all select 2 as no, 'bbb' as str""")
spark.sql("select * from temp_view_t").show()
#+---+---+
#| no|str|
#+---+---+
#| 1|aaa|
#| 2|bbb|
#+---+---+
#to eliminate duplicates we can use union also.
spark.sql("""create or replace temporary view temp_view_t as select * from temp_view_t union select 1 as no, 'aaa' as str""")
spark.sql("select * from temp_view_t").show()
#+---+---+
#| no|str|
#+---+---+
#| 1|aaa|
#| 2|bbb|
#+---+---+
Hope it helps. Kindly accept the answer by clicking on Accept answer
button. Thankyou