Queryset Union

2017-10-17 Thread Matthew Pava
Hi fellow users, I came across a situation where I needed to annotate a union-all query. Django's ORM is so powerful, and it has those features separately, but it cannot seem to handle annotating a union-all query. I was able to solve my problem by using two views inside PostgreSQL. I created

Re: queryset union

2009-09-17 Thread Tim Chase
> Then you'll need to use SQL. There's no way to do UNION in Django's > ORM. > > An alternative is just to concatenate the two querysets: > union = list(x) + list(y) Or if the results are large and you don't want to consume double the memory, you can use itertools.chain() from itertools imp

Re: queryset union

2009-09-17 Thread Daniel Roseman
On Sep 17, 5:05 pm, blumenkraft wrote: > Did you mean or(|) instead of and(&)? Yes, sorry. > I need SQL UNION for efficiency reasons (using UNION instead of SQL > generated by > models.Advertisement.objects.filter( Q(company__name__search="test") | > Q(contact__phone__istartswith="8495") is 60x

Re: queryset union

2009-09-17 Thread blumenkraft
Did you mean or(|) instead of and(&)? I need SQL UNION for efficiency reasons (using UNION instead of SQL generated by models.Advertisement.objects.filter( Q(company__name__search="test") | Q(contact__phone__istartswith="8495") is 60x faster in my case) On Sep 17, 7:51 pm, Daniel Roseman wrote:

Re: queryset union

2009-09-17 Thread Daniel Roseman
On Sep 17, 3:39 pm, blumenkraft wrote: > Hi, > > I have two querysets: > x = models.Advertisement.objects.filter(company__name__search = > "test") > y = models.Advertisement.objects.filter(contact__phone__istartswith = > "8495") > > Is there any simple way to get union (using SQL UNION clause) of

queryset union

2009-09-17 Thread blumenkraft
Hi, I have two querysets: x = models.Advertisement.objects.filter(company__name__search = "test") y = models.Advertisement.objects.filter(contact__phone__istartswith = "8495") Is there any simple way to get union (using SQL UNION clause) of these querysets? --~--~-~--~~~-