Re: Escape percent sign in QuerySet.extra()

2012-12-02 Thread Joseph Mutumi
Sorry I hadn't seen your comment, have you tried %%% ?

On Mon, Dec 3, 2012 at 7:28 AM, Joseph Mutumi  wrote:

> I think to escape a % use %%
>
>
> On Sun, Dec 2, 2012 at 1:16 PM, Martin Svoboda 
> wrote:
>
>> Hi,
>> I want use postgresql pg_trgm module in django. pg_trgm defines special
>> operator percent sign. How should I escape it in django query extra method?
>>
>> # Pure SQL
>> SELECT content, similarity(content, 'text') AS sml
>>   FROM table
>>   WHERE content % 'text'
>>   ORDER BY sml DESC, content;
>>
>> # Extra throws IndexError 'tuple index out of range'
>> # I tried escape % with %%, or \%, but it throws same exception
>> objects = MyModel.objects.extra(
>> select={'rank': 'similarity(content, %s)'},
>> select_params=[content],
>> where='content % %s',
>> params=[content],
>> order_by=['-rank']
>> )
>>
>> # Raw query works fine
>> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS
>> rank FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''',
>> [content, content])
>>
>> How should I escape persent sign in extra() method?
>>
>> Thank you!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/2euBM5lHjZEJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Escape percent sign in QuerySet.extra()

2012-12-02 Thread Joseph Mutumi
I think to escape a % use %%

On Sun, Dec 2, 2012 at 1:16 PM, Martin Svoboda wrote:

> Hi,
> I want use postgresql pg_trgm module in django. pg_trgm defines special
> operator percent sign. How should I escape it in django query extra method?
>
> # Pure SQL
> SELECT content, similarity(content, 'text') AS sml
>   FROM table
>   WHERE content % 'text'
>   ORDER BY sml DESC, content;
>
> # Extra throws IndexError 'tuple index out of range'
> # I tried escape % with %%, or \%, but it throws same exception
> objects = MyModel.objects.extra(
> select={'rank': 'similarity(content, %s)'},
> select_params=[content],
> where='content % %s',
> params=[content],
> order_by=['-rank']
> )
>
> # Raw query works fine
> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS rank
> FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''', [content,
> content])
>
> How should I escape persent sign in extra() method?
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/2euBM5lHjZEJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Escape percent sign in QuerySet.extra() method

2012-12-02 Thread Chris Cogdon


On Sunday, December 2, 2012 1:55:05 AM UTC-8, Martin Svoboda wrote:
>
> Hello,
> I'm want to use functionality of postgresql module 
> pg_trgmin django. 
> pg_trgm uses special operator % (percent sign). I don't know how 
> should I escape it in query extra method.
>
> # pure SQL
> SELECT content, similarity(content, 'string') AS sml
>   FROM table
>   WHERE content % 'str'
>   ORDER BY sml DESC, content;
>
> # This throws exception IndexError 'tuple index out of range'
> # I tried to escape percent sign with %%, or \%, but I always get same 
> exception
> objects = MyModel.objects.extra(
> select={'rank': 'similarity(content, %s)'},
> select_params=[content],
> where='content % %s',
> params=[content],
> order_by=['-rank']
> )
>
> # Raw query works ok
> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS sml 
> FROM table WHERE content %% %s ORDER BY sml DESC''', [content, content])
>
> Can you help me how write percent sign in extra() method?
>

While this should not fix anything, can you try breaking it down like so.

objects = MyModel.objects.extra(
where='content % %s',
params=[content],
)

objects = objects.extra(
select={'rank': 'similarity(content, %s)'},
select_params=[content],
order_by=['-rank']
)

That'll give us a hint at which of the two parts are giving us a problem.


>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2EovB167MRIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Escape percent sign in QuerySet.extra() method

2012-12-02 Thread Martin Svoboda
Hello,
I'm want to use functionality of postgresql module 
pg_trgmin django. 
pg_trgm uses special operator % (percent sign). I don't know how 
should I escape it in query extra method.

# pure SQL
SELECT content, similarity(content, 'string') AS sml
  FROM table
  WHERE content % 'str'
  ORDER BY sml DESC, content;

# This throws exception IndexError 'tuple index out of range'
# I tried to escape percent sign with %%, or \%, but I always get same 
exception
objects = MyModel.objects.extra(
select={'rank': 'similarity(content, %s)'},
select_params=[content],
where='content % %s',
params=[content],
order_by=['-rank']
)

# Raw query works ok
objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS sml 
FROM table WHERE content %% %s ORDER BY sml DESC''', [content, content])

Can you help me how write percent sign in extra() method?

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/N7BT4BFV11oJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Escape percent sign in QuerySet.extra()

2012-12-02 Thread Martin Svoboda
Hi,
I want use postgresql pg_trgm module in django. pg_trgm defines special 
operator percent sign. How should I escape it in django query extra method?

# Pure SQL
SELECT content, similarity(content, 'text') AS sml
  FROM table
  WHERE content % 'text'
  ORDER BY sml DESC, content;

# Extra throws IndexError 'tuple index out of range'
# I tried escape % with %%, or \%, but it throws same exception
objects = MyModel.objects.extra(
select={'rank': 'similarity(content, %s)'},
select_params=[content],
where='content % %s',
params=[content],
order_by=['-rank']
)

# Raw query works fine
objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS rank 
FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''', [content, 
content])

How should I escape persent sign in extra() method?

Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2euBM5lHjZEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.