1

以下 SQL 完美运行:

SELECT node_path, commenttext
FROM comments WHERE node_path ~ '*.5f985c80_5205_48cd_b198_1734e0a981d4.*';

但是以下给了我一个错误:

SELECT node_path, commenttext
FROM comments WHERE node_path ~ ('*.'||'5f985c80_5205_48cd_b198_1734e0a981d4'||'.*');

错误是:

ERROR:  operator does not exist: ltree ~ text
LINE 1: ...e_path, commenttext FROM comments WHERE node_path ~ ('*.'||'...
                                                             ^
HINT:  No operator matches the given name and argument type(s).
You might need to add explicit type casts.

除了串联之外,我不确定两者之间的区别。

4

1 回答 1

1

我想到了。在连接末尾添加::lquery使其工作。所以总的来说,这是解决方案:

SELECT node_path, commenttext FROM comments WHERE node_path ~ ('*.'||'5f985c80_5205_48cd_b198_1734e0a981d4'||'.*')::lquery;

我用这个来弄清楚:

https://www.postgresql.org/message-id/CA+mi_8a2t_d9qbD83SBxwY_OKM1c4iHnceXPOM4fP9X=WGeYfQ@mail.gmail.com

于 2019-09-16T02:50:35.403 回答