Larry Martell
unread,Feb 20, 2017, 10:50:44 AM2/20/17Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Is there any way to use both the ORM and raw SQL in the same query?
I have an existing app that uses the ORM and now I have a need to add
SQL like this to the select:
(CASE
WHEN TRIM(IFNULL(roiname, '')) IN ('', 'None') THEN CONCAT_WS('.',
roi_type_id, roi_id)
WHEN CONCAT_WS('.', roi_type_id, roi_id) = roiname THEN roiname
ELSE CONCAT_WS('.', roi_type_id, roi_id, roiname)
END) as roiname
and SQL like this to the where:
AND (CASE
WHEN TRIM(IFNULL(roiname, '')) IN ('', 'None') THEN CONCAT_WS('.',
roi_type_id, roi_id)
WHEN CONCAT_WS('.', roi_type_id, roi_id) = roiname THEN roiname
ELSE CONCAT_WS('.', roi_type_id, roi_id, roiname)
END) REGEXP 'foo'
As far as I know I cannot do anything like that with the ORM. I don't
want to have to rewrite everything with raw SQL. Is there a way to mix
them?