sql-update

Bulk UPDATE table with WHERE clause that is variable

心不动则不痛 提交于 2020-08-25 03:47:43
问题 I have a bunch of pairs of values [(foo1, bar1), (foo2, bar2), ...] and I want to do a bunch of updates of "set the 'foo' column to 'foo1' where the 'bar' column is 'bar1'". I am doing this in Python with psycopg2. I could do executemany with the query UPDATE table SET foo = %s WHERE bar = %s , but that's a lot of little updates and would take mad long. How can I do this easily and fast? Perhaps something with a temp table? Postgres version 9.3. 回答1: UPDATE tbl t SET foo = v.foo FROM ( VALUES

Update table set column equal to select where id matches outside of query in oracle

时光毁灭记忆、已成空白 提交于 2020-08-10 20:12:31
问题 This seems simple but I can't seem to wrap my head around it... I am trying to update a table, set the columns equal to the result of a query which uses the ID column from the table which I am updating and uses a WITH() clause. I also only want to update the columns in my table where Fall_Term = 'Fall 2019' I will provide my pseudo code and my long nasty actual code... NOTE: My update statement works perfectly fine if I manually enter values for the ID column - PERSON_SKEY. For example,