Thread: count(*) in binary mode returns 0

count(*) in binary mode returns 0

From
"imagenesis@gmail.com"
Date:
I have an implementation of binary format communication that is working quite well but it is failing inexplicably on returning valid results for the aggregate function count. It returns a correct result for instance for the aggregate function max. 

Here is some debug information to illustrate that I have debugged the host order conversions and what have you in implementing this binary format. As you can see, it is simply returning 0.

s:select count(*) from "User" where ("email" = $1)
valsl 1
result received
free_iter_pre
alloc_result pre
fname: count
nfields: 1
from_psql 00000000000000000000000000000000 bytes_to_read:4 read:4
host_order 00000000000000000000000000000000 bytes_to_read:4 read:4
conv_int ir:0
fname: count

Re: count(*) in binary mode returns 0

From
Tom Lane
Date:
"imagenesis@gmail.com" <imagenesis@gmail.com> writes:
> I have an implementation of binary format communication that is working
> quite well but it is failing inexplicably on returning valid results for
> the aggregate function count. It returns a correct result for instance for
> the aggregate function max.

> Here is some debug information to illustrate that I have debugged the host
> order conversions and what have you in implementing this binary format. As
> you can see, it is simply returning 0.

Offhand I'd bet that you're mistransmitting the statement parameter so
that the WHERE condition never succeeds.  You could set log_statement=all
and look in the postmaster log to see what the server thinks it's getting.

            regards, tom lane


Re: count(*) in binary mode returns 0

From
"Daniel Verite"
Date:
    imagenesis@gmail.com wrote:

> nfields: 1
> from_psql 00000000000000000000000000000000 bytes_to_read:4 read:4
> host_order 00000000000000000000000000000000 bytes_to_read:4 read:4
> conv_int ir:0

Note that count(*) produces a bigint (8 bytes), not an int (4 bytes).

=> select pg_typeof(count(1));
 pg_typeof
-----------
 bigint
(1 row)

Can you check if your code does work when the query is simply
SELECT 1::bigint ?


Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite