gpt4 book ai didi

sql - hstore:无法连接两个 hstore 值

转载 作者:行者123 更新时间:2023-11-29 12:04:58 25 4
gpt4 key购买 nike

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 中的两个 hstore 值连接起来吗?

感谢任何指点!

最佳答案

您可以按原样使用 CAST 函数:

SELECT CAST(p.properties->'name' AS text) || CAST(p.properties->'age' AS text) FROM people p where p.id=1;

关于sql - hstore:无法连接两个 hstore 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28977940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com