postgrespro/jsquery

Escaping double quotes

GrandFelix opened this issue · 2 comments

Hi,

how I can escape double quotes in values ?

select * from statements_json t where t.data @@ '"u:ba#title".* ($ = "something  "" '' ")' and t.version is null;

select * from statements_json t where t.data @@ '"u:ba#title".* ($ = "something  \" '' ")' and t.version is null;

For both cases I get:

ERROR: bad jsquery representation Detail: syntax error, unexpected STRING_P, expecting OR_P or AND_P or ')' at or near " "

Any tip how I should escape double quotes in values ? Escaping single quotes is OK, but double quotes are not.

What's value of standard_conforming_strings option? Second option works for me with "standard_conforming_strings = on";
For "standard_conforming_strings = off" try:
select * from statements_json t where t.data @@ '"u:ba#title".* ($ = "something \\" \' ")' and t.version is null;
Or even better, use version independent on standard_conforming_strings option:
select * from statements_json t where t.data @@ E'"u:ba#title".* ($ = "something \\" \' ")' and t.version is null;

Thank you very much.

Yes, we have standard_conforming_strings turned off and your solution works!

One more question. You escape single quotes ' with . Can I escape them with '' or it must be escaped with ' ? Because '' does work too.

Thank you Alexander.