Friday, June 21, 2019

Update using columns from subquery

I'm new to the community (this is my first topic here) so I apologize if I'm breaking any rules with this post.

My goal is to update a table in my Postgres db using the values from a queryset only where some of the values are equal to the columns in my table. Essentially, I'd like to do the following:

UPDATE schema.table t1 SET t1.value = t2.value FROM ( SELECT id1, id2, value FROM does_not_matter ) t2 WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2 In this example, t2 represents my queryset. It can contain potentially hundreds of thousands of rows (distinct on (id1, id2)).

Is there any way to accomplish this using the django ORM? I'm using version 1.11

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a2ca8f74-cc05-41c7-bee9-4f981ead3538%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment