Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do an INSERT with VALUES in Databricks into a Table

I have a simple table with the following columns

ID int
DESC nvarchar(255)

This table is mapped via JDBC as a table in Databricks. I want to do insert like in SQL Server:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

I have found the following example in the Databricks documentation but i dont have a partition i have columns.

-- Appends two rows into the partition (p1 = 3, p2 = 4)
INSERT INTO data_source_tab1 PARTITION (p1 = 3, p2 = 4)
  SELECT id FROM RANGE(1, 3)

How can i do this in Azure Databricks?

like image 672
STORM Avatar asked Oct 14 '25 18:10

STORM


1 Answers

I have solved it by using the following command:

%sql
INSERT INTO TABLE tempSQLSimpleTable2 VALUES ('Hi', 2)

Usage: INSERT INTO TABLE tempSQLSimpleTable2 VALUES ([value_column_1], [value_column_2], ...)

Only the column data is provided in the order of the columns, not the columns names.

This works for me, but if i should be wrong with my above statement that you have to insert for all columns than please comment or correct.

like image 69
STORM Avatar answered Oct 18 '25 02:10

STORM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!