Re: How to pivot a table?
I am not sure what database you are using, but I just did this using a raw query and postgresql's crosstab function. http://www.postgresql.org/docs/current/static/tablefunc.html http://docs.djangoproject.com/en/1.2/topics/db/sql/#executing-custom-sql-directly On Feb 18, 7:25 am, Derekwrote: > On Feb 17, 10:52 pm, Phlip wrote: > > > > > > > Djangoists: > > > I have a database table like this... > > > red, 1 > > red, 2 > > red, 15 > > blue, 18 > > blue, 20 > > > ...and I want to read it into an array like this: > > > [ ['red', [1,2,15]], ['blue', [18,20]], ] > > > Of course I can use values_list('color', 'number'), and then re-pack > > the array with a for-loop. > > > Do QuerySet aggregations and annotations offer some way to push that > > query into the database? > > Assuming you want an output in array format (as per the first part of > your > question):http://stackoverflow.com/questions/1859031/how-could-create-a-crossta... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to pivot a table?
On Feb 17, 10:52 pm, Phlipwrote: > Djangoists: > > I have a database table like this... > > red, 1 > red, 2 > red, 15 > blue, 18 > blue, 20 > > ...and I want to read it into an array like this: > > [ ['red', [1,2,15]], ['blue', [18,20]], ] > > Of course I can use values_list('color', 'number'), and then re-pack > the array with a for-loop. > > Do QuerySet aggregations and annotations offer some way to push that > query into the database? Assuming you want an output in array format (as per the first part of your question): http://stackoverflow.com/questions/1859031/how-could-create-a-crosstab-sql-query-with-django-orm -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to pivot a table?
Djangoists: I have a database table like this... red, 1 red, 2 red, 15 blue, 18 blue, 20 ...and I want to read it into an array like this: [ ['red', [1,2,15]], ['blue', [18,20]], ] Of course I can use values_list('color', 'number'), and then re-pack the array with a for-loop. Do QuerySet aggregations and annotations offer some way to push that query into the database? -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.