Update using columns from subquery

15 views
Skip to first unread message

Dean Rabinowitz

unread,
Jun 21, 2019, 4:20:08 PM6/21/19
to Django users
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
Reply all
Reply to author
Forward
0 new messages