Home > database >  Failed insert in Snowflake with JSON containing '$$'
Failed insert in Snowflake with JSON containing '$$'

Time:01-13

I'm escaping JSON before inserting into my Snowflake table. However, if the JSON itself contains the Snowflake escape quotes ($$) it will fail. Is there a way around this? If I remove the '$$' from the JSON then it inserts successfully however I need to retain the original JSON. Is there a way around this without removing the $$ characters? Thanks

insert into yaml_files
      select column1 as path,
      parse_json(column2) as yaml
      from values ('test',$${'example': 'blahblah','example2': 'asdf$$6lkj'}$$);

CodePudding user response:

As the comments noted, you can use single quotes for strings instead of $$.

Error reproduced:

select parse_json($${"a":"b$$c"}$$);

Fixed:

select parse_json('{"a":"b$$c"}');

If there's a single quote inside the string, escape it with \:

select parse_json('{"a":"b\'$$c"}');
  •  Tags:  
  • Related