Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are generating the values on the fly using phyton, you could:</p> <ol> <li>Create a buffer containing a single <code>INSERT</code> statement</li> <li>Start a transaction</li> <li>Create a temporary table and perform the <code>INSERT</code> statement in your buffer</li> <li>Perform an <code>UPDATE ... FROM</code></li> <li>Commit the transaction, discarding the temporary table.</li> </ol> <p>The <code>UPDATE</code> statement will look like this (assuming there is a table <code>new_values</code> containing those new values you need to update):</p> <pre><code>UPDATE app_post AS a SET text_location = n.text_location FROM new_values AS n WHERE a.id = n.id </code></pre> <p>Don't forget to define the columns <code>id</code> as <strong>PRIMARY KEY</strong> or create an index on them.</p> <hr> <p><strong>EDIT</strong> : Since you are experiencing very slow performance, another workaround could be to recreate the whole table. The following idea assumes you don't have any <code>FOREIGN KEY</code> constraint applied to <code>app_post</code> table, as you have shown in your initial post.</p> <pre><code>-- Begin the Transaction BEGIN; -- Create a temporary table to hold the new values CREATE TEMPORARY TABLE temp_update_values ( id integer PRIMARY KEY, text_location integer ) ON COMMIT DROP; -- Populate it INSERT INTO temp_update_values (id, text_location) VALUES (1, 123), (2, 456) /* ... #5000 total */ ; -- Create a temporary table merging the existing "app_post" and "temp_update_values" CREATE TEMPORARY TABLE temp_new_app_post ON COMMIT DROP AS SELECT a.id, COALESCE(n.text_location, a.text_location) AS text_location, a.title FROM app_post AS a LEFT JOIN temp_update_values AS n ON a.id = n.id; -- Empty the existing "app_post" TRUNCATE TABLE app_post; -- Repopulate "app_post" table INSERT INTO app_post (id, text_location, title) SELECT id, text_location, title FROM temp_new_app_post; -- Commit the Transaction COMMIT; </code></pre> <p>If there are any <code>FOREIGN KEY</code> constraint, you should take care of them, dropping them before TRUNCATING the <code>app_post</code> table, and re-creating them after it's been repopulated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload