Sql 如何从任何hstore值中选择一行?
我在PostgreSQL(9.5)数据库中有一个表Sql 如何从任何hstore值中选择一行?,sql,postgresql,hstore,Sql,Postgresql,Hstore,我在PostgreSQL(9.5)数据库中有一个表Content,其中包含列title。title列是一个hstore。这是一个hstore,因为标题被翻译成不同的语言。例如: example=# SELECT * FROM contents; id | title | content | created_at
Content
,其中包含列title
。title
列是一个hstore
。这是一个hstore
,因为标题
被翻译成不同的语言。例如:
example=# SELECT * FROM contents;
id | title | content | created_at | updated_at
----+---------------------------------------------+------------------------------------------------+----------------------------+----------------------------
1 | "de"=>"Beispielseite", "en"=>"Example page" | "de"=>"Beispielinhalt", "en"=>"Example conten" | 2016-07-17 09:20:23.159248 | 2016-07-17 09:20:23.159248
(1 row)
我的问题是,我如何选择内容
,其中标题
包含示例页面
SELECT * FROM contents WHERE title = 'Example page';
不幸的是,这个查询不起作用
example=# SELECT * FROM contents WHERE title = 'Example page';
ERROR: Syntax error near 'p' at position 8
LINE 1: SELECT * FROM contents WHERE title = 'Example page';
您应该在where子句中使用like
SELECT * FROM contents WHERE title like '%Example page%';
希望它能帮助您。函数avals()
返回hstore
列中所有值的数组。然后,您可以使用any
与该数组匹配您的值:
select *
from contents
where 'Example page' = any(avals(title))
title
是一个hstore
列。您不能在hstore
上使用LIKE
是否可以强制转换为varchar数据类型?错误:运算符不存在:hstore~~unknown