postgreSQL hstore如果包含值
发布时间:2020-12-13 15:58:34 所属栏目:百科 来源:网络整理
导读:有没有办法检查查询本身的hstore中是否已存在值. 我必须每行存储各种值(每行是“项目”). 我需要能够检查id是否已存在于其中一个hstore行的数据库中,而不是首先选择所有内容并在php中执行循环等. hstore似乎是唯一提供类似内容的数据类型,并且还允许您将该行
有没有办法检查查询本身的hstore中是否已存在值.
我必须每行存储各种值(每行是“项目”). Hstore可能不是存储这类数据的最佳数据类型,但没有其他更好的可用. 整个项目使用9.2,我无法改变 – json是9.3. 解决方法
exists()函数测试是否存在密钥.确定密钥“42”是否存在于hstore中的任何位置. . .
select * from (select test_id,exist(test_hs,'42') key_exists from test) x where key_exists = true; test_id key_exists -- 2 t svals()函数将值作为集合返回.您可以查询结果以确定是否存在特定值. select * from (select test_id,svals(test_hs) vals from test) x where vals = 'Wibble'; hstore Operators and Functions create table test ( test_id serial primary key,test_hs hstore not null ); insert into test (test_hs) values (hstore('a','b')); insert into test (test_hs) values (hstore('42','Wibble')); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |