我在 PostgreSQL (9.5) 数据库中有一个表 Content
,其中包含 title
列。 title
列是一个 hstore
。这是一个 hstore
,因为 title
被翻译成不同的语言。例如:
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)
我的问题是,如何选择 title
包含 Example page
的 content
?
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';
最佳答案
avals()
函数返回 hstore
列中所有值的数组。然后,您可以使用 any
对该数组匹配您的值:
select *
from contents
where 'Example page' = any(avals(title))
关于sql - 如何从任何 hstore 值中选择一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38422166/