﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7106	django.db extra() method fails	aribao@…	nobody	"Hello, I use to work with PostgreSQL, and with full-text enabled. To get full-text working I used the extra() method. After updating to the last svn version with the database refactor, this was broken. I use a custom manager to get the results.


{{{
class NewsManager( models.Manager ):
    def get_query_set(self):
        return super(NewsManager, self).get_query_set().filter( status = 2 ).order_by('-dateTimeCreated')

class news( models.Model ):
    dateTimeCreated = ...
    ...
    status = ( here I define the status of the item: published, deleted, awaiting aproval... )
    
    #The visible manager only shows the news whose state is ""published""
    visible = NewsManager()
}}}


There is a problem with the positions of the arguments, and autoscaping the table name.
This is the code I use:

{{{
words = 'here the words i want to search'
items = items.extra(
                    select={
                        'headline': ""ts_headline(description, query,'StartSel = <strong>, StopSel = </strong>')"",
                        'rank': ""ts_rank_cd(tsv, query, 32)"",
                        },
                    tables=[""plainto_tsquery(%s) as query""],
                    where=[""tsv @@ query""],
                    params=[ words ]
                    ).order_by('-rank')
}}}

This is the SQL generated:

{{{
SELECT COUNT(*) FROM ""app_news"" , ""plainto_tsquery(2) as query"" WHERE ""app_news"".""status_id"" = E\'words to search\' AND tsv @@ query
}}}


As you can see, the position of the arguments is wrong, and ""plainto_tsquery(2) as query"" shouldn't be between double quotes.

"		closed	Database layer (models, ORM)	dev		wontfix	db database wrapper	aribao@…	Unreviewed	0	0	0	0	0	0
