whateverMan
whateverMan

Reputation: 65

Got invalid expression error , while inserting JSON data into VARIANT column

Trying to insert multiple rows into a snowflake table

insert into sample_table  (a, b, c) values ('foo','bar',parse_json($${"def": 1}$$)),('doo','bam',parse_json($${"def": 1}$$));

Have tried replacing '$$' with single quotes

Getting error:

SQL compilation error: Invalid expression [PARSE_JSON('{"def":1}')] in VALUES clause

What am I doing wrong?

Upvotes: 4

Views: 4106

Answers (1)

Simeon Pilgrim
Simeon Pilgrim

Reputation: 25903

You cannot use PARSE_JSON in the values section. But you can do a

create table sample_table(a text, b text, c variant);
insert into sample_table 
  select column1, column2, parse_json(column3) from values
    ('foo', 'bar', '{"def": 1}'),
    ('doo', 'bam', '{"def": 1}');
number of rows inserted
2

Upvotes: 8

Related Questions