Here is my schema and data
create table mytable (id numeric, val text);
create table mytable1 (id1 numeric, id text);
insert into mytable values (123, 'aaa');
insert into mytable values (124, 'bbb');
insert into mytable values (125, 'ccc');
insert into mytable1 values (1001, '[123]');
insert into mytable1 values (1002, '[123,124]');
insert into mytable1 values (1003, '[123,124,125]');
When I am running the below query, I am getting expected result.
select string_to_array(trim(mt1.id, '[]'), ',')::numeric[] from mytable1 mt1 where mt1.id1 = 1003
Result:
123,124,125
But, when I am passing the above query as inner query for a select query, I am not getting the result
select mt.val from mytable mt where mt.id = any (select string_to_array(trim(mt1.id, '[]'), ',')::numeric[] from mytable1 mt1 where mt1.id1 = 1003)
Expected result:
val
---
aaa
bbb
ccc
Anything wrong in the query?
(using Postgresql-9.1)