【发布时间】:2012-12-26 05:06:52
【问题描述】:
如何从 Postgres 表中的 ltree 中删除特定标签?我有桌子吗?
测试表:
CREATE TABLE tbl (sno int, path ltree, userid int);
INSERT INTO tbl (sno, path, userid)
VALUES
(1, '123', 123)
, (2, '123.101', 123)
, (3, '123.101.103', 123)
, (4, '123.101.103.105', 123)
, (5, '123.101.103.107', 123)
, (6, '123.102.104.106', 123)
, (7, '123.102.104.108', 123)
, (8, '123.102.104', 123)
, (9, '123.102', 123);
我想将 userid 传递给查询,以将其从表中的每个 path 中删除。例如,如果我通过101,那么123.101.103 应该更新为123.103。
是否可以直接执行此操作?还是我应该使用路径替换功能更新path?
我从 PHP 中尝试了以下选择查询,但它返回以下错误。相同的查询在 phpPgAdmin 中正常工作!?
查询:
$selectPathq=pg_query($con,"select path from myschema.test where path @ '101'")
or die('could not connect: '. pg_last_error($con));
错误:
could not connect: ERROR: operator does not exist: myschema.ltree @ unknown at character 63 HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
【问题讨论】:
-
供读者阅读。 解决丑陋的“运算符不存在”错误(为什么PostgreSQL没有修复它??)的魔法是使用替换运算符
@operator(public.@)(或@>等)如答案中所述。不需要对您的代码进行其他更改。
标签: sql postgresql tree sql-update postgresql-9.1