With Postgres and Psycopg2, make sure your subquery returns more than zero 
records.

Postgres and Psycopg2 raise an exception when the belongs set is empty.



On Monday, October 1, 2012 1:35:14 PM UTC-4, Richard wrote:
>
> Instead passing your tag, pass an inverse tag selection where you omit you 
> tag, then use not belongs : ~link.tag_id.belongs(subquery)...
>
> Where subquery will something like that :
>
> subquery=db(~db.TAGTABLE.TAGNAME.belongs((tag1,tag2,tagEtc))).select(
> db.TAGTABLE.TAGNAME.id)
>
> Richard
>
> On Sat, Sep 29, 2012 at 1:51 PM, andrej burja 
> <andrej...@gmail.com<javascript:>
> > wrote:
>
>> hi
>>
>> another question:
>> there is number of tags: n = len(tags)
>> and there is 
>> rows = db(data.id==link.record_id)\
>>     (link.tag_id.belongs(subquery)).select(
>>     data.ALL,
>>     orderby=data.id,
>>     groupby=data.id,
>>     having=data.id.count()==n)
>>
>> so, if i have data1 with tags (news, sport) and data2 with tags (news, 
>> sport, football)
>> and searching for tags: news, sport
>>
>> is the result data1 only or data1 and data2
>> if later, how to search for data with exactly entered tags (omit data 
>> with more tags)
>>
>> andrej
>>
>>
>> On Monday, September 24, 2012 5:57:35 PM UTC+2, andrej burja wrote:
>>>
>>> hi
>>>
>>> it works
>>> thank you
>>>
>>> andrej
>>>
>>> On Sunday, September 23, 2012 12:18:32 AM UTC+2, Massimo Di Pierro wrote:
>>>>
>>>> Looks like postgres is picky and wants in groupby all the selected 
>>>> fields in distinct. This should work:
>>>>
>>>> rows = db(data.id==tag.record_**id)\
>>>>     (tag.name.belongs(tags)).sel**ect(
>>>>        data.ALL,
>>>>        orderby=data.id,
>>>>        groupby=data.id|data.value,
>>>>        distinct=True)
>>>>
>>>> On Saturday, 22 September 2012 15:00:07 UTC-5, andrej burja wrote:
>>>>>
>>>>> the code with problem:
>>>>>
>>>>> rows = db(data.id==tag.record_id)\
>>>>>     (tag.name.belongs(tags)).selec**t(
>>>>>        data.ALL,
>>>>>        orderby=data.id,
>>>>>        groupby=data.id,
>>>>>        distinct=True)
>>>>>
>>>>>
>>>>>
>>>>> On Saturday, September 22, 2012 10:26:27 AM UTC+2, andrej burja wrote:
>>>>>>
>>>>>> hi 
>>>>>>
>>>>>> i would like to use idea in book Application Development Cookbook - 
>>>>>> Efficienty search by tag. 
>>>>>> there are two functions: 'search_or' and 'search_and'
>>>>>> everything is working fine on sqlite
>>>>>> when i switch to postgres, there seems to be problem with 'groupby'. 
>>>>>> i got an error 
>>>>>>
>>>>>> <class 'psycopg2.ProgrammingError'> column "data.value" must appear 
>>>>>> in the GROUP BY clause or be used in an aggregate function LINE 1: 
>>>>>> SELECT 
>>>>>> DISTINCT data.id, data.value FROM tag, data WHERE ((d... ^
>>>>>> when i remove 'groupby=....id" there is no error, but (of course) 
>>>>>> 'search_and' function doesn't work properly
>>>>>>
>>>>>> is this a bug related to postgres?
>>>>>>
>>>>>> andrej
>>>>>>
>>>>>  -- 
>>  
>>  
>>  
>>
>
>

-- 



Reply via email to