I'm able to create a schema in databricks but how can I insert data into the array and map? I just cannot find any information regarding SQL. It's all about python, scala, but I'm looking for sql only.
CREATE TABLE IF NOT EXISTS mydb.arraytest (
capacity array<INT>,
mapper MAP<INT, STRING>,
device_type STRING,
location_id INT
)
Gives me the expected schema:
+-------------+-----------------+
| col_name | data_type |
+-------------+-----------------+
| capacity | array<int> |
| mapper | map<int,string> |
| device_type | string |
| location_id | int |
# Partitioning
Not partitioned
But I just don't know how can I insert values into the array and the map?
None of what I tried worked:
INSERT INTO
mydb.arraytest
VALUES
(array<1,2,3>, (1, 'mapstring1'), 'string1', 1)
(<1,2,3>, ....
The Array and Map functions start with brackets, so something like this should work for you:
%sql
INSERT INTO arraytest
VALUES (Array(1,2,3), Map(1, 'mapstring1'), 'string1', 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With