首页 > 解决方案 > 单个 Postgres 数据库表列中的多个值

问题描述

我最近接任了一个我不熟悉的应用程序的数据库管理员。我正在探索开发数据库实例,并在单个列中找到了一个包含多个值的表。我不确定如何查询此列,因为到目前为止我尝试过的方法都没有奏效。

我在列名和列值本身中看起来像键值对的内容之间尝试了各种字符。我正在尝试根据 state :name 值进行选择。以下都没有工作,我还没有找到解决这个问题的 postgres 文档。

select * from district where state = 'California';

select * from district where state:name = 'California';

select * from district where state_name = 'California';

select * from district where state[name] = 'California';

select * from district where state[:name] = 'California';
select * from district where state[0] = 'California';

以下是来自表区的特定条目

id         | 8
name       | 13
state      | --- + | :name: California + | :abbr: CA + |
created_at | 2011-12-08 04:31:15.104002
updated_at | 2011-12-08 04:31:15.104002

标签: databasepostgresql

解决方案


尝试正则表达式:

WHERE name  ~ '\mCalifornia\M'

推荐阅读