I want to extract an element from a json in a column.
However, the key of the element I am interested contains % (the exact name is: Use%).
Following this, I tried to use double quotes, however, I still have the same problem:
JSON_VALUE(results, '$."Use%"') as value
JSON text is not properly formatted. Unexpected character ''' is found
at position 1.
JSON_VALUE(results, '$.Use%') as value
JSON path is not properly formatted. Unexpected character '%' is found
at position 5.
How can I extract the value from my json string ?
The JSON is the following:
{'Filesystem': 'hdfs://nameservice1', 'Size': '67945349394432', 'Used': '22662944968704', 'Available': '41812184838144', 'Use%': '33%'}
The problem isn't your attempt, it's your JSON; it isn't valid JSON. JSON uses double quotes (") for delimit identifing not single quotes ('). For the example we have, simply REPLACEing the single quotes with double quotes fixes the problem:
DECLARE #YourJSON nvarchar(MAX) = N'{''Filesystem'': ''hdfs://nameservice1'', ''Size'': ''67945349394432'', ''Used'': ''22662944968704'', ''Available'': ''41812184838144'', ''Use%'': ''33%''}';
SELECT JSON_VALUE(REPLACE(#YourJSON, '''', '"'), '$."Use%"') AS value;
Of course, I strongly suggest you investigate how you are creating JSON which uses single quotes, rather than double quotes, and fix both your existing data and process that creates it.
Related
I wanted to use the SELECT ARRAY['foo','bar','foo bar','foo,bar','foo.bar'] and the output of it to insert into a field with datatype of text[]. But the out ut of the above SELECT ARRAY query gave me a strange response where the text with spaces/commas were present it wrapped them in double quotes. Any help how to get data without double quotes.
I have tried with ARRAY_AGG function too still the same response
I'm attempting to copy out from a Snowflake table to a CSV on S3 using the "copy into" command.
I noticed that using the following parameters in my copy into statement leads to ALL fields in the entire CSV file being enclosed in double quotes.
file_format=(type=csv compression=none field_optionally_enclosed_by='"' empty_field_as_null=false null_if='' trim_space=true field_delimiter=',') header=true overwrite=true single=true;
Is this expected behavior for the field_optionally_enclosed_by option? I thought that just the fields containing commas in the value would be enclosed by "", but all fields in the full file are enclosed.
Is there another option to see the output that I want? I'd like just the fields containing a comma in the value to be enclosed, but the rest not enclosed.
That's expected behaviour as it's explained here:
https://docs.snowflake.com/en/user-guide/data-unload-considerations.html#empty-strings-and-null-values
FIELD_OPTIONALLY_ENCLOSED_BY = 'character' | NONE
Use this option to
enclose strings in the specified character: single quote ('), double
quote ("), or NONE.
The same parameter is also used when ingesting data, this is why its name is "FIELD_OPTIONALLY_ENCLOSED_BY". When you use this parameter on loading, it doesn't expect all values are enclosed by this character, but they may be enclosed optionally.
Of course, there could be a smarter way to apply this parameter. For example, when the data contains the field_delimiter character, it could be enclosed. This could be a good feature request.
I have a table with a single Varchar column and a row with value A”B”C .
While downloading it from snowflake UI as a CSV file the result shows A””B””C
.
In this case if you are using Data Unloading feature, you need to use File format in the copy into statement.
In the file format you need to use the option "FIELD_OPTIONALLY_ENCLOSED_BY "
Ref - https://docs.snowflake.com/en/user-guide/data-unload-considerations.html#empty-strings-and-null-values
When a field contains this character, escape it using the same character. For example, if the value is the double quote character and a field contains the string "A", escape the double quotes as follows: ""A"".
In the Json output data fields the leading and trailing quotes of the string of array type has to be removed. The json data is getting displayed in the workato. We tried with ruby methods like gsub, delete_prefix, delete_suffix but it didn't worked in removing the quotes of the string of array type in workato.
Would someone suggest the solutions to remove the leading and trailing quotes of string array in ruby with workato.
Sample example image of string of array with quotes:
The output data hash looks like an array, but with only 1 string [["a"]]
It is normal that Workato displays the output enclosed by " (double quotation marks), but the real string is only [["a"]]
If you insert the data DataPill in a Lookup Table, you should not see the double quotation marks anymore
I am reading data from a table and updating into other table in SQLite. while reading it is not showing any error. But while it is updating it is showing error because the text i am going to update contains "You're" it is showing error for 're--> this apps' re. Any way to update with this special character?
Insert another single quote after You' so that the text becomes "You''re"
http://sqlite.org/lang_expr.html
A string constant is formed by enclosing the string in single quotes ('). A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal. C-style escapes using the backslash character are not supported because they are not standard SQL.