Hi. I’m trying to assign a database table row count to a variable.
Using:
Postgrex.query!(pid, "select count(*) from sometable", [])
If the table has few rows, eg 73, the result is an ascii character in a list:
%Postgrex.Result{
columns: ["c"],
command: :select,
connection_id: 103477,
messages: [],
num_rows: 1,
rows: ['I']
}
If the table has many rows the result is an integer in a nested list:
%Postgrex.Result{
columns: ["count"],
command: :select,
connection_id: 103477,
messages: [],
num_rows: 1,
rows: [[1632691]]
}
The results are seemingly inconsistent, and my theories (charlist related) to explain them are no better.
Firstly, why?
Secondly, which function should I use for accessing the values consistently across both scenarios.
Eg Using hd/1 is no good as it differs for each case: hd(small_result) vs hd(hd(big_result))
Thanks.