sql - Postgres: Update all columns from another table -


i need update table one, , need update columns, questions that, besides list every column in set, there way update them this:

update tablea set * = tableb.* tableb tablea.id = tableb.id 

i tried in psql, doesn't work.. have list every column this:

update tablea set c1 = tableb.c1, c2 = tableb.c2, ... tableb tablea.id = tableb.id 

tableb created use create..like tablea. identical. , reason i'm doing need load .csv data temp table tableb , update tablea based on new data in tableb. tablea needs locked little possible , tablea needs keep integrity. i'm not sure 'delete insert' option?

thanks!

you delete , re-insert, if 2 tables have same columns in same order. assuming records in tableb match tablea:

delete tablea     id in (select id tableb)  insert tablea     select *     tableb; 

(if records not match, use temporary table keep necessary ids.)

generally, oppose doing insert without column list. in cases, tolerable -- such when tableb created subset tableb using *.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -