我有两张桌子:
Molecule
包含:
- id
- MainName
(例如:咖啡因)
JsonTextMining
包含:
- id
- solrId
(例如:PMC54233)
- MoleculeName
(例如:咖啡因|阿司匹林|糖)
它们是ManyToMany关系,因此第三个表jsonTextMiningMolecule
具有:
- json_text_mining_id
- molecule_id
我想找到一个postgresql命令,可以拆分moleculeName
字符串,然后与mainName
进行比较,以jsonTextMiningMolecule
目前我有这样的事情:
编辑:
update json_text_mining_molecule SET molecule_id = molecule.id
FROM molecule, json_text_mining
WHERE split_part(json_text_mining.molecule_name, ' | ', 2 ) = molecule.main_name
此命令的结果是更新0(perhap的,因为我对json_text_mining_id
有非空约束)而split_part不起作用,因为他需要选择字符串的一部分
答案 0 :(得分:0)
尝试查看split_part
命令。
https://www.postgresql.org/docs/9.1/static/functions-string.html
你可以在那里找到许多其他字符串操作!
编辑:
使用regexp_split_to_array
子句
IN