STORM
STORM

Reputation: 4331

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?

Upvotes: 4

Views: 14334

Answers (1)

STORM
STORM

Reputation: 4331

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.

Upvotes: 3

Related Questions