我有一张中间表:
text_mining_molecule
|text_mining_id| molecule_id |
| -------------| ---------- |
| ID | ID |
和另外两张表:
TableMolécules:
id | main_name | others …
--- | --------- | ------
1 | caféine | others …
表jsonTextMining:
id | title | molecule_name | others …
---|------- |-------------------------------------|------
1 | title1 | colchicine, cellulose, acid, caféine| others …
如果在列表中选择了来自其他2个表text_mining_molecule
和json_text_mining
的ID,则需要插入 molecule
。
实际上,当选择低于4的分数时,有一个下拉列表已插入json_text_mining
到text_mining
的所有行。
INSERT INTO text_mining (id, solrid, originalpaper, annotatedfile, title, keyword, importantsentence, version, klimischscore, moleculename, synonymname, validation)
SELECT id, solrid, originalpaper, annotatedfile, title, keyword, importantsentence, version, klimischscore, molecule_name, synonym_name, validation
FROM json_text_mining WHERE klimischscore < 4
这有效,但我需要text_mining_molecule
填写相关的ID,所以我也有这部分代码:
SELECT s.id, m.id
FROM (SELECT id, regexp_split_to_table(molecule_name,', ') AS m_name
FROM json_text_mining) AS s, molecule m
WHERE m.main_name = s.m_name;
如何使用text_mining_molecule
而不是insert
直接更新select
表?
答案 0 :(得分:0)
使用CTE。例如,如果text_mining_molecule.molecule
引用molecule.id
,那就像是:
with c as (
SELECT s.id sid, m.id mid
FROM (SELECT id, regexp_split_to_table(molecule_name,', ') AS m_name
FROM json_text_mining) AS s, molecule m
WHERE m.main_name = s.m_name
)
update text_mining_molecule t
set sid = c.sid
from c
where t.molecule = c.mid