有没有一种简单的方法可以找到完整路径并为具有这种数据结构的所有主题更新它。
TOPIC_0000070
|
TOPIC_0000054
/ | \
TOPIC_0000000 TOPIC_0000001 TOPIC_0000002
- 初始数据:
CREATE TABLE topics (id varchar, path ltree);
INSERT INTO "topics"(id, path) VALUES ('TOPIC_0000000', 'TOPIC_0000054.TOPIC_0000000');
INSERT INTO "topics"(id, path) VALUES ('TOPIC_0000001', 'TOPIC_0000054.TOPIC_0000001');
INSERT INTO "topics"(id, path) VALUES ('TOPIC_0000002', 'TOPIC_0000054.TOPIC_0000002');
INSERT INTO "topics"(id, path) VALUES ('TOPIC_0000054', 'TOPIC_0000070.TOPIC_0000054');
INSERT INTO "topics"(id, path) VALUES ('TOPIC_0000070', 'TOPIC_0000070');
id | path |
-------------+---------------------------+
TOPIC_0000000|TOPIC_0000054.TOPIC_0000000|
TOPIC_0000001|TOPIC_0000054.TOPIC_0000001|
TOPIC_0000002|TOPIC_0000054.TOPIC_0000002|
... |... |
TOPIC_0000054|TOPIC_0000070.TOPIC_0000054|
TOPIC_0000070|TOPIC_0000070 |
- 预期结果:
id | path |
-------------+-----------------------------------------+
TOPIC_0000000|TOPIC_0000070.TOPIC_0000054.TOPIC_0000000|
TOPIC_0000001|TOPIC_0000070.TOPIC_0000054.TOPIC_0000001|
TOPIC_0000002|TOPIC_0000070.TOPIC_0000054.TOPIC_0000002|
... |... |
TOPIC_0000054|TOPIC_0000070.TOPIC_0000054 |
TOPIC_0000070|TOPIC_0000070 |