After creating users
stream with its interests
field as a string array ARRAY<STRING>
data type:
CREATE STREAM users
(userid VARCHAR,
interests ARRAY<STRING>)
WITH (KAFKA_TOPIC = 'users',
VALUE_FORMAT='JSON');
I go ahead and insert the first user data with:
INSERT INTO users (userid, interests) VALUES ('user0001', ['music','sport'])
Unfortunately this insert statement fails with an error
line 1:60: extraneous input '[' expecting {'(', 'STRING'...
I tried to replace the square bracket []
with ()
as:
INSERT INTO users (userid, interests) VALUES ('user0001', ('music','sport'))
but it fails too.
How to fix this error? Is there a way to store a sting array ['music','sport']
using string array data type ?
You have to use the ARRAY
function:
https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-reference/scalar-functions/#array
INSERT INTO users (userid, interests) VALUES ('user0001', ARRAY['music','sport']);