Thanks! Here's a polished version of that: https://github.com/django/django/pull/5095
Let me know if it makes sense. On Monday, August 3, 2015 at 9:10:00 AM UTC-4, Anssi Kääriäinen wrote: > > On Mon, Aug 3, 2015 at 2:07 PM, Tim Graham <timog...@gmail.com > <javascript:>> wrote: > > Is there an example we could give in the docs to point readers in that > > direction? > > There doesn't seem to be direct documentation about RawSQL expression. > The RawSQL is once mentioned in the documentionation, but it > definitely needs a bit more in the database functions documentation. > > The usage of RawSQL is really simple: > qs.annotate(val=RawSQL("(select col from sometable where othercol > = %s)", (someparam,))) > > This is equivalent to qs.extra(select={'val': "select col from > sometable where othercol = %s"}, select_params=(someparam,)) > > The main benefit of using RawSQL is that you can set output_field if > needed. The main downside is that if you refer to some table alias of > the qs in the raw sql, then it is possible that Django changes that > alias (for example, when the qs is used as a subquery in yet another > query). > > Combining raw SQL with alias relabeling support is possible, too with > the following library: https://github.com/akaariai/django-refsql > > - Anssi > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/70c66320-4af4-41ee-9df7-18facd3b82b2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.