You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Kyle Lilly <ky...@immuta.com> on 2019/08/08 15:28:04 UTC

SQL equality predicate escaping single quotes

Hi,

When using the SQL handler is there any way to escape single quotes in
boolean predicates? A query like:

SELECT title FROM books WHERE author_lastname = 'O''Reilly'

Will return no results for authors with the last name "O'Reilly" but will
return hits for books with a last name of "OReilly". I can perform a
standard Solr term search using "lastname:O'Reilly" and get back the
expected results. Looking through the code it appears all single quotes are
stripped from term values in the SQL handler -
https://github.com/apache/lucene-solr/blame/1d85cd783863f75cea133fb9c452302214165a4d/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java#L136.
If this is by design is there any way to use single quotes in a term
predicate with SQL?

Thanks.

- Kyle

Re: SQL equality predicate escaping single quotes

Posted by Joel Bernstein <jo...@gmail.com>.
It does appear that single quotes are being removed. If you want to provide
a patch that allows single quotes to get passed through, I can help with
testing and committing.


On Thu, Aug 8, 2019 at 11:28 AM Kyle Lilly <ky...@immuta.com> wrote:

> Hi,
>
> When using the SQL handler is there any way to escape single quotes in
> boolean predicates? A query like:
>
> SELECT title FROM books WHERE author_lastname = 'O''Reilly'
>
> Will return no results for authors with the last name "O'Reilly" but will
> return hits for books with a last name of "OReilly". I can perform a
> standard Solr term search using "lastname:O'Reilly" and get back the
> expected results. Looking through the code it appears all single quotes are
> stripped from term values in the SQL handler -
>
> https://github.com/apache/lucene-solr/blame/1d85cd783863f75cea133fb9c452302214165a4d/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java#L136
> .
> If this is by design is there any way to use single quotes in a term
> predicate with SQL?
>
> Thanks.
>
> - Kyle
>