The PostgreSQL (PG) field is separated by a comma "," to determine if a value is included

Source: Internet
Author: User
Tags postgresql

If there is a student student table

The fields in the Student Table have field course fields with 1,2,3,4,5,6,7 7 courses

CREATE TABLE Student

(

Name varchar (255),

Course varchar (255)

)

INSERT into student (name, course)

Values (' Zhang San ', ' 1,2,5,7 ');


Question one, judge whether Zhang San chose course 2

SELECT * FROM

where name = ' Zhang San '

and String_to_array (course, ', ') @> array[' 2 ']


Question two, judge whether Zhang San chooses the course at the same time 2,6

SELECT * FROM

where name = ' Zhang San '

and String_to_array (course, ', ') @> array[' 2 ', ' 6 ']


This article is from a "simple to rely" blog, so be sure to keep this source http://wenxuehui.blog.51cto.com/12898974/1954697

The PostgreSQL (PG) field is separated by a comma "," to determine if a value is included

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.