@Aguardientico is absolutely correct that you want the array to overlap with the && operator. I follow some explanations, but would prefer you to accept this answer rather than this one.
Anonymous strings (entries)
The construct ('item1', 'item2', ...) is the constructor of the string if it does not appear in the IN (...) list. It creates an anonymous string, which PostgreSQL calls a "record". Error:
ERROR: operator does not exist: record = character varying
is that ('Arms', 'Chest') interpreted as if it were ROW('Arms', 'Chest') , which produces a single record value:
craig=> SELECT ('Arms', 'Chest'), ROW('Arms', 'Chest'), pg_typeof(('Arms', 'Chest')); row | row | pg_typeof --------------+--------------+----------- (Arms,Chest) | (Arms,Chest) | record (1 row)
and PostgreSQL doesn't know how this should compare to a string.
I do not like this behavior; I would prefer PostgreSQL to require explicit use of the ROW() constructor when you want an anonymous string. I expect that the behavior given here exists to support SET (col1,col2,col3) = (val1,val2,val3) and other similar operations in which the ROW(...) constructor will not make any sense.
But what works with one element?
The reason why the only one ('Arms') works is because if there is no comma, this is just one brace value, where the brackets are redundant and can be ignored:
craig=> SELECT ('Arms'), ROW('Arms'), pg_typeof(('Arms')), pg_typeof(ROW('Arms')); ?column? | row | pg_typeof | pg_typeof ----------+--------+-----------+----------- Arms | (Arms) | unknown | record (1 row)
Do not worry about the unknown type. It just means that it is a string literal that has not yet used the type:
craig=> SELECT pg_typeof('blah'); pg_typeof ----------- unknown (1 row)
Comparing an array with a scalar
It:
SELECT * FROM "db_of_exercises" WHERE "body_part" IN ('Arms', 'Chest');
failure:
ERROR: array value must start with "{" or dimension information
due to implicit casting. The body_part column body_part is text[] (or varchar[] , the same in PostgreSQL). You compare it for equality with the values ββin the IN clause, which are letters with a typed type. The only valid equality operator for an array is = another array of the same type, so PostgreSQL shows that the values ββin the IN clause must also be text[] arrays and try to parse them as arrays.
Since they are not written as array literals such as {"FirstValue","SecondValue"} , this parsing is not performed. Note:
craig=> SELECT 'Arms'::text[]; ERROR: array value must start with "{" or dimension information LINE 1: SELECT 'Arms'::text[]; ^
Cm?
Itβs easier to understand this as soon as you see that IN is actually just a shorthand for = ANY . This is a comparison of equality with each item in the IN list. This is not what you need if you really want to find out if two arrays overlap.
So why do you want to use array overlap with the && operator.