I'm working with an existent database that have an array field (Phones) with the IDs from another table, I'm new to this kind of feature, how can I get all records of Public_Phone that are recorded into User->Phones Array?
User Table
+---------------------------------------+
|ID | User | Phones(int array) | Email|
+---------------------------------------+
| 1 | 11922 | {12,23,56} | none |
Public_Phone Table
+-------------------------------------+
|ID | Location | Color | AR | Line_FK |
+-------------------------------------+
Note: The database was upgraded recently to 9.4
Thanks in advance.
Taking in count the @nullReference comments I'm trying this
SELECT *
FROM Public_Phone pp
WHERE pp.id IN (1,5)
That's work
But querying for user[3] using a subquery:
SELECT *
FROM Public_Phone pp
WHERE pp.id IN( SELECT Phones FROM User u WHERE u.id=3)
I got:
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
ERROR: operator does not exist: integer = integer[]
Using
SELECT *
FROM Public_Phone pp
WHERE pp.id = ANY( SELECT Phones FROM User u WHERE u.id=3)
Is the same
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
********** Error **********
ERROR: operator does not exist: integer = integer[]