I am using JSON_EXTRACT()
to retrieve the date from json.
I want to get the date without double quotes.
Here is the example of what I am doing :
JSON_EXTRACT(JSON_EXTRACT(events, "$.my_member"), "$.my_Number") as xyz
my_number
holds date string as "2016-01-01 11:31:25", I want this without the double quotes.
I tried using timestamp as :
timestamp(JSON_EXTRACT(JSON_EXTRACT(events, "$.my_member"), "$.my_Number"))
but it is returning a null value to xyz.
Thanks.
Use the String. replaceAll() method to remove all double quotes from a string, e.g. str. replaceAll('"', '') . The replace() method will return a new string with all double quotes removed.
The simplest method to escape single quotes in SQL is to use two single quotes. For example, if you wanted to show the value O'Reilly, you would use two quotes in the middle instead of one. The single quote is the escape character in Oracle, SQL Server, MySQL, and PostgreSQL.
Use two single quotes to escape them in the sql statement. The double quotes should not be a problem: SELECT 'How is my son''s school helping him learn?
REPLACE(item_description, '"', '') will absolutely remove any " from the column.
Try
JSON_EXTRACT_SCALAR(JSON_EXTRACT(events, "$.my_member"), "$.my_Number")
Also, you should be able to further "optimize" your expression by building proper JSON Path and using JSON function only ones. See "hint" below
SELECT
JSON_EXTRACT_SCALAR(
'{"my_member":{"my_Number":"2016-01-01 11:31:25"}}',
"$.my_member.my_Number"
)
See more details and also difference between JSON_EXTRACT_SCALAR and JSON_EXTRACT at JSON functions
Run REPLACE
REPLACE(JSON_EXTRACT(JSON_EXTRACT(events, "$.my_member"), "$.my_Number"),"\"","") as xyz
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