hstore: 无法连接两个hstore值

3

我刚开始接触Postgres,使用的是v9.3版本,想要利用hstore

当我尝试连接两个hstore值时,出现了一个奇怪的错误:

SELECT p.properties->'name' || p.properties->'age' FROM people p where p.id=1;

错误信息为:
ERROR:  operator does not exist: text -> unknown
LINE 1: select n.properties->'name' || n.properties->'age' from n...
                                                   ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

我也尝试过这个方法,但并没有起到作用:
SELECT p.properties->'name'::text || p.properties->'age'::text FROM people p where p.id=1;

然而,我可以做到。
SELECT p.properties->'name' FROM people p where p.id=1;

SELECT p.properties->'age' FROM people p where p.id=1;

是否可以将两个来自同一个hstore的值连接起来?

非常感谢任何指导!

1个回答

4
您可以使用CAST函数来完成以下操作:
SELECT CAST(p.properties->'name' AS text) || CAST(p.properties->'age' AS text) FROM people p where p.id=1;

问题已解决。原来只需要对第二个及其后的hstore引用进行CAST,第一个可以保持不变。很奇怪。感谢您的帮助! - Will Kessler

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接