As is so often the case, the requirements changed. Now what I had to
do, if I was doing it in SQL would have been:
(CASE
WHEN TRIM(IFNULL(roiname, '')) IN ('', 'None') THEN CONCAT_WS('.',
CONVERT(roi_type_id, CHAR), roi_id)
WHEN CONCAT_WS('.', CONVERT(roi_type_id, CHAR), roi_id) = roiname THEN roiname
ELSE CONCAT_WS('.', CONVERT(roi_type_id, CHAR), roi_id, roiname)
END) REGEXP '%s'
But the table I am selecting from has 600,000 rows or more, and that
query would cause a table scan. So I did not add that to the existing
query, and instead iterated over the result set in python and did that
filtering.
Queries like that aren't "compatible" with Django ;)
You may also consider creating a view and map it to a unmanaged django model, but do not forget to add on_delete/on_update=DO_NOTHING for FKs.
But I have no idea what Django migration system do with such mapped view - I kicked off builtin migrations completely and I am using Liquibase to manage dbs.
Marcin
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+unsubscribe@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/ecccc784-6a38-4bcc-9341-b2f6a59b97c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment