0

The db is PostgreSQL. When I try to execute a query with parameters, such as this one

cursor.execute("""
    SELECT u.username, up.description, 
        ts_rank_cd(to_tsvector(coalesce(username,'')|| coalesce(description,'')) , to_tsquery('%s')) as rank

        FROM auth_user u INNER JOIN pm_core_userprofile up on u.id = up.user_id
        WHERE to_tsvector(coalesce(username,'')|| coalesce(description,'')) @@ to_tsquery('%s')
        ORDER BY rank DESC;
    """, ["hello","hello"])

Django complains of a ProgrammingError, adding syntax error at or near the parameter (in this example, "hello"). Here's the part of the Django generated SQL statement that the error comes from:

to_tsquery('E'hello'')

Even if I copy-paste it to a postgreSQL shell, I get the syntax error. If I omit the 'E' part, it works. What should I make of it?

2 Answers 2

2

ozgur,

Try

to_tsquery(%s)

instead of

to_tsquery('%s')
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! This is embarrassing, I think I better take a vacation asap :)
Would have been more embarrassing if I had guessed wrong...I'm more used to SQL Server syntax. ;)
0

I believe you are missing a ' after the E.

1 Comment

The E stuff is put there by Django ORM, I just pass a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.