Sql 为什么在Postgres中查询LTREE时字符串连接不起作用?

Sql 为什么在Postgres中查询LTREE时字符串连接不起作用?,sql,postgresql,concatenation,postgres-9.6,ltree,Sql,Postgresql,Concatenation,Postgres 9.6,Ltree,以下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'||'.*');

以下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.

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

我找到了答案。在连接结束时添加
::lquery
,可以使其正常工作。因此,总体而言,解决方案如下:

SELECT node_path, commenttext FROM comments WHERE node_path ~ ('*.'||'5f985c80_5205_48cd_b198_1734e0a981d4'||'.*')::lquery;
我用这个来解决这个问题: