I have a simple query that returns count.
select count(*)
from table
wehre ....
I would like the count to return as an INTEGER and not a STRING. The default in Postgres seems to be String.
I have tried to do this:
select cast(count(*) as INTEGER)
....
but it's not working. The query runs, but the type of count is still a string. I've tried other ways unsuccessfully.
Is there a way to have the count return as an number instead of a string type?
EDIT:
As I checked the type of the result table in DataGrip it does show that the count return is of type "count: Int".
What threw me off is the result as returned in Postman. The query select is this:
select person.age, count(*) from ....
When that query runs in the endpoint it's in, Postman shows this as result:
[{"age":18, count: "45"}, ....]
So, then I assumed that the count form Postgres was coming back as a string because the age (INTEGER type on the table) does return back as a number type and not a string. So, now I am confused as to why one column type is right, and the other is not (count...).
The query is run using Sequelize:
const result = await sequelize.query(query, { type: sequelize.QueryTypes.SELECT });
and then return straight via:
res.status(200).json(result)
select pg_typeof(count(*)) from cell_per; bigint. How are you seeing/determining it is a string?agehas a declared type in the model(?) for the table, whereascountis generated and cast as a string as a default type.count(*)as a string.