insert into doc_fulltext(docid, fulltext) select d.id as docid, t.fulltext as fulltext from document d left outer join temp_fulltext t on (d.id = t.pubid) where t.fulltext is not null;