Using postgres ts_rank's normalization parameter in django?

2017-02-14 Thread Thomas Nyberg

Hello,

I've been looking at the documentation on this page:

https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/search/

I am trying to use the postgres ts_rank function as exposed through 
django. The ts_rank function in postgres can be called in (at least) two 
ways:


* ts_rank(tsvector, tsquery)
* ts_rank(tsvector, tsquery, normalization)

The normalization integer is documented here (textsearch for normalization):

https://www.postgresql.org/docs/current/static/textsearch-controls.html

I don't see in the documentation where this is exposed in the django 
side of things. How do I make use of that option?


Thanks for any help and sorry if I'm just blindly missing something 
obvious in the documentation.


Cheers,
Thomas

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3fb397fc-8c3a-6e8f-19b2-46fd3fabd215%40gmx.com.
For more options, visit https://groups.google.com/d/optout.


Re: How see raw SQL code produced by django?

2017-02-13 Thread Thomas Nyberg

On 02/13/2017 05:24 PM, Tim Graham wrote:



Here's where Django defines REGEXP:
https://github.com/django/django/blob/2f10216f84b55920de25422842a66260219e393f/django/db/backends/sqlite3/base.py#L173

From http://stackoverflow.com/a/8244670:

SQLite does not contain regular expression functionality by default.

It defines a REGEXP operator, but this will fail with an error message
unless you or your framework define a user function
 called regexp().

You can execute raw SQL on a Django connection using the technique
documented at
https://docs.djangoproject.com/en/stable/topics/db/sql/#connections-and-cursors.



Excellent thanks so much this clarifies a lot and is great info!

Cheers,
Thomas

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a03833d2-a64b-209a-3317-6691c11dce36%40gmx.com.
For more options, visit https://groups.google.com/d/optout.


How see raw SQL code produced by django?

2017-02-13 Thread Thomas Nyberg

Hello,

I have a question about regexes and sqlite3. I am executing a certain 
line of code:


>>> regex = 'NET | INCOME'
>>> Table.objects.filter(name__iregex=regex).

When I have it print out the SQL sent, I get the following (this is a 
simplified, but equivalent version):


SELECT *
FROM "table"
WHERE "table"."name"
REGEXP '(?i)' || 'NET | INCOME'
LIMIT 21

However if I execute that directly against the sqlite database i get the 
following error:


sqlite3.OperationalError: no such function: REGEXP

I thought that maybe this magic was handled in python's sqlite3 module, 
but if i do it there i get the same error. So basically my question is, 
can anyone tell me where this is transformed into regular sql? it 
obviously happens somehwere (I get no error when running in django after 
all), but I can't for the life of me figure out where.


Thanks a lot!

Thomas

PS: I have tried using the shell_plus --print-sql extension, but that 
shows me the same thing.


PPS: Obviously not django-related, but if anyone knows how to get a 
sqlite database to log all queries issued against it, that would also 
obviously solve this issue.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a78c6d8a-4284-ec8a-9757-cf49da7b38b9%40gmx.com.
For more options, visit https://groups.google.com/d/optout.