Re: parameterized full text search problem

From: Joe Abbate <jma(at)freedomcircle(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Re: parameterized full text search problem
Date: 2013-03-13 01:10:19
Message-ID: 513FD1FB.8060402@freedomcircle.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: psycopg

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.

> 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.

Joe

In response to

Browse psycopg by date

  From Date Subject
Next Message Don Parris 2013-03-13 09:21:10 Fwd: parameterized full text search problem
Previous Message Don Parris 2013-03-13 00:47:26 parameterized full text search problem