Fwd: parameterized full text search problem

From: Don Parris <parrisdc(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Fwd: parameterized full text search problem
Date: 2013-03-13 09:21:10
Message-ID: CAJ-7yonWneeEinTgMQ=uWKMZuKQExxexmcKXZTQ3Dfgs=SC1BA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: psycopg

Because I forgot to pay attention to the e-mail headers.... Sorry about
that! Anyway, this one is solved.

---------- Forwarded message ----------
From: Don Parris <parrisdc(at)gmail(dot)com>
Date: Tue, Mar 12, 2013 at 9:30 PM
Subject: Re: [psycopg] parameterized full text search problem
To: Joe Abbate <jma(at)freedomcircle(dot)com>

On Tue, Mar 12, 2013 at 9:05 PM, Joe Abbate <jma(at)freedomcircle(dot)com> wrote:

> On 12/03/13 20:47, Don Parris wrote:
> > I want the user to be able to pass in the search term at runtime,
> > something akin to:
> > search_term = input(Search Payee: )
> > cur.execute("""SELECT * FROM entity WHERE to_tsvector(%s, entity_name)
> > @@ to_tsquery(%s, %s);""",
> > ("english" "english", search_term))
>
> You're missing a comma betwen the two "english" words.
>

With the commas between the two "english" words did not change much.

>
> > I tried this approach (from the example in the documentation, using
> > %(str)s in place of %s:
> > cur.execute("""SELECT * FROM entity WHERE to_tsvector(%(str)s,
> > entity_name) @@ to_tsquery(%(str)s, %(str)s);""",
> > {'str': "english", 'str': "english", 'str': search_term})
>
> You need to give each unique element to be replaced a unique name, like
>
> """SELECT * FROM entity WHERE to_tsvector(%(lang)s,
> entity_name) @@ to_tsquery(%(lang)s, %(term)s);"""
> {'lang': "english", 'term': search_term}
>
> I suggest you read about Python dictionaries as well.
>
> Thanks Joe. Partly, was taking the example in the documentation a little
too seriously (using "str"). Silly me. There is one other catch. I was
passing in two words from the command line: "compare foods".
Using just "compare" by itself brought up the record. As long as I pass
only one word of the field value I am searching for, it works. It breaks
when I enter anything more.

BUT... it *does* work. I probably should code an exception for when the
user tries to type in more than one word at the prompt to catch that and
offer them a second chance.

Thanks again!
Don
--
D.C. Parris, FMP, Linux+, ESL Certificate
Minister, Security/FM Coordinator, Free Software Advocate
http://dcparris.net/
<https://www.xing.com/profile/Don_Parris><http://www.linkedin.com/in/dcparris>
GPG Key ID: F5E179BE

--
D.C. Parris, FMP, Linux+, ESL Certificate
Minister, Security/FM Coordinator, Free Software Advocate
http://dcparris.net/
<https://www.xing.com/profile/Don_Parris><http://www.linkedin.com/in/dcparris>
GPG Key ID: F5E179BE

In response to

Browse psycopg by date

  From Date Subject
Next Message Jan Wrobel 2013-03-13 11:32:33 Is it allowed to reuse a connection on which another thread waits for notifications?
Previous Message Joe Abbate 2013-03-13 01:10:19 Re: parameterized full text search problem