database – the dynamic query with NOT IN does not work correctly

I used the clause NOT IN & # 39; repeatedly in my drupal 7 code, without checking the results. But now, a special situation has caught my attention. I have to exe a query to a separate database by selecting people who do not have e-mail. In sql is

SELECT id, name, name FROM people WHERE id NOT IN (SELECT person_id FROM email);

As usual, I translated this request into

db_set_active ('extdb');
$ ids = db_query (& # 39; select person_id from email where address is not null) -> fetchCol ();
$ query = db_select ('person', & # 39; p & # 39;);
$ query-> fields ('p', table ('id', 'name', & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;) & # 39;);
$ query-> condition (& # 39; p.id & # 39 ;, $ ids, & # 39; NOT IN & # 39;);
$ result = $ query-> execute ();
db_set_active (& # 39; default & # 39;);

but I do not get any results, and that's wrong. But if I check outside the query, the result is correct. Like that:

db_set_active ('extdb');
$ ids = db_query (& # 39; select person_id from email where address is not null) -> fetchCol ();
$ query = db_select ('person', & # 39; p & # 39;);
$ query-> fields ('p', table ('id', 'name', & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;) & # 39;);
$ result = $ query-> execute ();
db_set_active (& # 39; default & # 39;);
$ items = array ();
foreach ($ result as $ row) {
if (! in_array ($ row-> id, $ ids))
$ items[] = $ row;
}

How is it possible?