Tables params in extra()

14 views
Skip to first unread message

Dave Lowe

unread,
May 13, 2008, 12:15:23 PM5/13/08
to Django developers
Ever since the querset-refactor merge, params in the 'tables' argument
don't seem to be filled. The documentation describes the arguments
'params' and 'select_params' as being for where and select statements,
respectively. Do we need a "tables_params" argument as well?

Here's a code sample of where I'm using tables params (it's for full-
text searching in postgres):

results = Product.objects.extra(
select={
'rank': "rank_cd(textsearchable,
query, 32)",
},
tables=["to_tsquery(%s) as query"],
where=["textsearchable @@ query"],
params=[terms],
order_by=('-rank',)
)

The error message by the way is: ProgrammingError: relation
"to_tsquery(2) as query" does not exist.

David Cramer

unread,
May 13, 2008, 12:59:47 PM5/13/08
to Django developers
The database engine usually can't fill that in anyways, you should
probably quote it yourself (correct me if I'm wrong).

Dave Lowe

unread,
May 13, 2008, 1:47:44 PM5/13/08
to Django developers
It worked prior to qsrf-merge. I have tried adding the quotes though,
without success.

Barry Pederson

unread,
May 14, 2008, 12:01:56 AM5/14/08
to django-d...@googlegroups.com, dave....@gmail.com

I've seen this too, also trying to do PgSQL FTS, and posted about it in
django-users

http://groups.google.com/group/django-users/browse_thread/thread/ef17cb9fff6d0391

it seems that two things are changed from pre-QSRF: params aren't
processed for the 'tables=' argument, and the tables= arguments are
quoted now, so you end up with something like

SELECT ... FROM "to_tsquery(%s) as query" ...

where before QSRF it would have executed

SELECT ... FROM to_tsquery('value of terms') as query ...

as a workaround, you can repeat the call to to_tsquery() and use
select_params=, as in:

--------

results = Product.objects.extra(
select={
'rank': "rank_cd(textsearchable,to_tsquery(%s), 32)",
},
where=["textsearchable @@ to_tsquery(%s)"],
params=[terms],
select_params=[terms],
order_by=('-rank',)
)

---------

Don't know how big of a hit it is to have to call to_tsquery() multiple
times even with the same args. But this isn't really just a fulltext
search issue, it could come up with other PgSQL functions that are more
heavyweight.

Barry

Dave Lowe

unread,
May 14, 2008, 12:31:58 AM5/14/08
to Django developers
I can't tell you how grateful I am that you posted this workaround,
Barry! Just in time for a site launch.

Like you said, I wonder if the multiple calls to to_tsquery() are
acceptable or if there's a more graceful solution here for the long-
term.
> http://groups.google.com/group/django-users/browse_thread/thread/ef17...
Reply all
Reply to author
Forward
0 new messages