I have a query which returns 0 rows but executing the same query using pgadmin or dbeaver returns a result set with rows.
Ive noticed this because i have a postgresql function which should return rows but didnt. After that i started debugging.
Other queries are not affected.
I tried it using knexjs (knex.raw()) and pg (client.query()).
Off cause, i checked the connection a dozen times using different queries and reading the connection string.
This is really strange.
The whole point here is, why does this work in dbeaver and not in my code. Is this a drivers thing?
Queries
select id from (
select id, started_at from queue
where finished_at is null and started_at is not null order by id
) d
where date_part('minute',age(now(), started_at)) >= 5
I played around a lot and found that the following queries do work.
select id from queue
where date_part('minute',age(now(), started_at)) >= 5;
and
select id from (
select id, started_at from queue
where finished_at is null and started_at is not null order by id
) d;
Update
not working
const test = await this.knexInstance.raw(`
select id from (
select id, started_at from queue
where finished_at is null and started_at is not null order by id
) d
where date_part('minute',age(now(), started_at)) >= 5
`);
console.log(test.rows); // => []
console.log(test.rows.length); // => 0
working
const test = await this.knexInstance.raw(`
select id from queue
where date_part('minute',age(now(), started_at)) >= 5;
`);
console.log(test.rows); // => Array(48083) [Object, Object, Object, Object, Object, Object, Object, Object, …]
console.log(test.rows.length); // => 48083