How to properly escape variables

32 views
Skip to first unread message

Sander Ferdinand

unread,
Apr 25, 2017, 8:55:46 AM4/25/17
to zom...@googlegroups.com
I was wondering how to deal with input strings that contain words/characters like:
  • "
  • and
  • or
For example:

SELECT [...] FROM products 
WHERE zdb('products', ctid) ==> 'short_description:"foo AND bar" AND price > 5'

Is the zdb expression `short_description = 'foo AND bar' AND price > 5` or is it `short_description = 'foo' AND bar AND price > 5` ? 

Are the quotes enclosing the query parameter? If this is the case, how could one escape double quotes? And when that doesn't happen, how could one use the `and` string as a query parameter?

I've found this issue; but I'm not a 100% sure how it works:


Thanks,
Sander

Sander Ferdinand

unread,
Apr 25, 2017, 11:32:54 AM4/25/17
to ZomboDB
Same goes for these wildcards: ? * ~ , can they escaped by prepending \ or is this simply not how ES works? :)

Sander Ferdinand

unread,
Apr 25, 2017, 11:35:39 AM4/25/17
to ZomboDB
Well, answering my own questions here: https://github.com/zombodb/zombodb/blob/master/SYNTAX.md#tokenization-escaping-case-sensitivity-and-term-analysis

Not sure how I missed that. My apologies!

Eric Ridge

unread,
Apr 25, 2017, 2:33:43 PM4/25/17
to ZomboDB
:)  Yep.  I was just about to link you that.  Let me know if that documentation isn't clear enough.  

Note that wildcard characters (*, ?, ~) *are* significant within "quoted phrases".  So if you want to search for one of those as a literal character within a "quoted phrase", you need to escape it.  For example:

     some_field:"Does \*this\* phrase contain wildcards\?"

eric

--
You received this message because you are subscribed to the Google Groups "ZomboDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zombodb+u...@googlegroups.com.
To post to this group, send email to zom...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zombodb/81f2067e-cbd4-4991-ab47-6acc34e73b9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sander Ferdinand

unread,
Apr 25, 2017, 4:42:11 PM4/25/17
to ZomboDB
Cheers for the clarification. Currently attempting to write a SQLAlchemy (ORM) plugin for the zdb query language, any bit of info helps :)

Eric Ridge

unread,
Apr 25, 2017, 11:27:15 PM4/25/17
to ZomboDB
Oh, cool! Definitely let me know if any of the docs need clarification. I'm happy to fix!

eric
Reply all
Reply to author
Forward
0 new messages