Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 0.56 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SQL script replacing column's data
  2. BEGIN;
  3.  
  4.     CREATE TEMPORARY TABLE tmp_table (id bigint PRIMARY KEY,
  5.         registrationnumber character varying(255));
  6.     INSERT INTO tmp_table
  7.     select id,registrationnumber from tableB;
  8.  
  9.     for d in tmp_table loop
  10.         update TABLEA set registrationnumber=d.id where
  11.             registrationnumber=d.registrationnumber;
  12.         return next d;
  13.     end loop;
  14.  
  15. END;
  16.        
  17. UPDATE tablea
  18.   SET registrationnumber = tableb.id
  19.   FROM tableb
  20.  WHERE tablea.registrationnumber = tableb.registrationnumber;
  21.  
  22. select * from tablea;