Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select by a word in a row from a column which has an array inside?

I have a column that contains an array of strings. I try to select the items which have a certain word in that column but I get this error:

function contains(character varying[], unknown) does not exist

This is my select query:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT "schedule", COUNT("schedule") AS "count" 
FROM "members" AS "member" 
WHERE contains("member"."facility_id", 'DEMO') 
GROUP BY "schedule"; 

>Solution :

If you want to test if an array of strings contains a specific element you need to use the contains operator which is @> but only works with arrays on both sides

WHERE member.facility_id @> array['DEMO']

To test for a single value, you can also use the any operator:

WHERE 'DEMO' = ANY(member.facility_id)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading