Wednesday, March 30, 2011

Re: Joins with multiple databases and temporary tables

for different databases the query could be formatted as
s=temp1.objects.using("mytemp").filter(refId=table1.objects.using("normal").get(pk=something).id)
where temp1 is table in database mytemp.table1 in databse normal
I cannot understand the get argument but may be if you give it a try
with a suitable args it may work."using" differentiates between
databases.

For the first problem;
may be if you get the cursor to the connection you want to keep
open and execute sql commands directly on it.This can be done as

from django.db import connections
cursor=connection["your_database_alias used in settings"].cursor()


On Mar 30, 10:39 pm, Gary Gendel <gagen...@gmail.com> wrote:
> I've got a strange situation and I was wondering how to handle it.
>
> The database has stored procedures that crunch on tables and store the
> results in temporary tables.  These resulting tables point to various
> records in persistent tables.
>
> The first question is how to control the connection in Django to leave
> the connection open so I don't lose the temporary tables before I'm
> finished working with them?
>
> The second part is a bit trickier.  The temporary tables are stored in
> a different database.  I don't want to get into why this was done, but
> I need is to override the database name in the models for the
> temporary tables.  I don't see a way to do this at the model level,
> only at the connection level.  How do I specify that the model is a
> table in a different database?  I want to end up with something like
> this:
>
> select ... from mytemp.temp1,normal.table1 where
> mytemp.temp1.refId=normal.table1.id;
>
> Thanks.
> Gary

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment