Couchbase N1QL: Updating fields containing single quotes, double quotes, orbackslash

Hi,

I’m having trouble updating fields assigning them with string that contains single quotes, double quotes, or backslash.

Example:
UPDATE key-space USE KEYS ‘id’ SET description= "John’s words are “Never give up” "

I tried updating field with back ticks and it just unset the field

I’m using Coubhase Server 5.0

UPDATE  default AS d USE KEYS  "k01" 
SET description= "John's words  are \"Never give up\". blackslash \\. ";

Hi @vsr1,

Thanks for your quick response. This works!

But, is there a built in function in N1QL where it will autamatically escape the quotation marks and backslashes?

Uou can’t void escape. strings must represent proper matching quotes

UPDATE  default AS d USE KEYS  "k01" 
SET description= "John's words  are \"Never give up\". blackslash \\. ";

Will set the description as John’s words are \“Never give up\”. blackslash \.

What I need is to store it as John’s words are “Never give up”. blackslash \.

If you filed is string type it must have in the quotes. If string want to contain another quotes it must be escaped.
https://www.json.org/json-en.html

It’s clearer now. It is impossible to store string without escaping double quotes and backslash. This will be handled on our end. Thank you.

Encountered another problem when the backslash is on the end of string followed by another field to update

UPDATE  default AS d USE KEYS  "k01" 
SET description= "John's words  are \"Never give up\". blackslash \\", title="Title 1"

Workaround . MB-38481

UPDATE  default AS d USE KEYS  "k01" SET description= "John's words  are \"Never give up\". blackslash \\",
 title='Title 1' ;

As our update is dynamic, this will cause problem esp on consecutive fields to update with backlash at the end of string