I have a table in a postgres database whose columns are shown below.
CREATE TABLE Student(
name VARCHAR,
course_id SMALLINT[]
);
I am trying to write a SQL query that fetches the name of the Student that has course_id 1 in its vector.
So if an entry has
INSERT INTO Student ( name, course_id ) VALUES ( 'john', ARRAY [1,2,3] );
The query will return ‘john’ since ‘john’ has a course_id 1
2
Answers
use postgres contains:
fiddle
You can use the
ANY()
operator: