Re: Custom SQL questions

2010-12-20 Thread Tim Sawyer
On 20/12/10 00:10, Andy wrote: On Dec 19, 6:20 pm, Tim Sawyer wrote: I think so, yes. Something like this: You can then do something like anObjectA = ObjectA.objects.filter(id=1)[0] objectBs = ObjectB.objects.filter(object_a=anObjectA) This requires 2

Re: Custom SQL questions

2010-12-19 Thread Andy
On Dec 19, 6:20 pm, Tim Sawyer wrote: > I think so, yes.  Something like this: > > You can then do something like > > anObjectA = ObjectA.objects.filter(id=1)[0] > objectBs = ObjectB.objects.filter(object_a=anObjectA) This requires 2 separate queries, right? I'm

Re: Custom SQL questions

2010-12-19 Thread Tim Sawyer
On 19/12/10 22:44, Andy wrote: On Dec 19, 5:06 pm, "Jonas H." wrote: On 12/19/2010 10:20 PM, Andy wrote: Is there a way to specify JOIN using the Django ORM? The 2 tables I'm joining aren't related through a foreign key. Why don't you use a relation field in your models

Re: Custom SQL questions

2010-12-19 Thread Andy
On Dec 19, 5:06 pm, "Jonas H." wrote: > On 12/19/2010 10:20 PM, Andy wrote: > > > Is there a way to specify JOIN using the Django ORM? The 2 tables I'm > > joining aren't related through a foreign key. > > Why don't you use a relation field in your models if your models are >

Re: Custom SQL questions

2010-12-19 Thread Erik Cederstrand
Den 19/12/2010 kl. 22.17 skrev Andy: > On Dec 19, 3:48 pm, Maksymus007 wrote: >> you get array of arrays. >> First array contains rows. Every row is just an array of fields, order is >> the same as in your query. > > What if my query is "SELECT * FROM ..."? > > In that

Re: Custom SQL questions

2010-12-19 Thread Jonas H.
On 12/19/2010 10:20 PM, Andy wrote: Is there a way to specify JOIN using the Django ORM? The 2 tables I'm joining aren't related through a foreign key. Why don't you use a relation field in your models if your models are related? -- You received this message because you are subscribed to

Re: Custom SQL questions

2010-12-19 Thread Steve Holden
On 12/19/2010 3:48 PM, Maksymus007 wrote: > you get array of arrays. Technically, in strict Python terms what you get is a list of tuples. Each element of the list is a tuple where each column from the query provides an element of each tuple. > First array contains rows. Every row is just an

Re: Custom SQL questions

2010-12-19 Thread Andy
> > I presume you already tried out to do your JOIN queries using the Django > ORM? Is there a way to specify JOIN using the Django ORM? The 2 tables I'm joining aren't related through a foreign key. -- You received this message because you are subscribed to the Google Groups "Django users"

Re: Custom SQL questions

2010-12-19 Thread Andy
On Dec 19, 3:48 pm, Maksymus007 wrote: > you get array of arrays. > First array contains rows. Every row is just an array of fields, order is > the same as in your query. What if my query is "SELECT * FROM ..."? In that case what ordering would the fields be in? --

Re: Custom SQL questions

2010-12-19 Thread Jonas H.
On 12/19/2010 09:45 PM, Andy wrote: I need to execute some SQL queries involving joins and it seems like custom SQL is the way to go. I presume you already tried out to do your JOIN queries using the Django ORM? A couple of questions: 1) In the doc

Re: Custom SQL questions

2010-12-19 Thread Maksymus007
you get array of arrays. First array contains rows. Every row is just an array of fields, order is the same as in your query. On Sun, Dec 19, 2010 at 9:45 PM, Andy wrote: > I need to execute some SQL queries involving joins and it seems like > custom SQL is the way to

Custom SQL questions

2010-12-19 Thread Andy
I need to execute some SQL queries involving joins and it seems like custom SQL is the way to go. A couple of questions: 1) In the doc (http://docs.djangoproject.com/en/1.2/topics/db/sql/ #executing-custom-sql-directly) there's an example: cursor.execute("SELECT foo FROM bar WHERE baz = %s",