postgresql (PG) 字段用逗号 “,”隔开 判断是否含有某个值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgresql (PG) 字段用逗号 “,”隔开 判断是否含有某个值相关的知识,希望对你有一定的参考价值。
如有一个student 学生表
student表中有字段 课程字段 分别用 1,2,3,4,5,6,7 表示不通的7门课程
CREATE TABLE student
(
name varchar(255),
course varchar(255)
)
insert into student (name ,course)
values (‘张三‘,‘1,2,5,7‘);
问题一、判断 张三 是否选择了 课程 2
select * from
where name = ‘张三‘
and string_to_array(course,‘,‘) @> array[‘2‘]
问题二、判断张三是否同时选择了课程2,6
select * from
where name = ‘张三‘
and string_to_array(course,‘,‘) @> array[‘2‘,‘6‘]
本文出自 “简单可依赖” 博客,请务必保留此出处http://wenxuehui.blog.51cto.com/12898974/1954697
以上是关于postgresql (PG) 字段用逗号 “,”隔开 判断是否含有某个值的主要内容,如果未能解决你的问题,请参考以下文章
postgresql copy from 文件,文件字段包含双引号怎么处理?
PostgreSQL 中系统表 pg_attribute 膨胀现象