Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8f2-0006V5-FE for pgsql-bugs@arkaria.postgresql.org; Sat, 18 Feb 2017 17:19:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cf8f2-0003lq-1j for pgsql-bugs@arkaria.postgresql.org; Sat, 18 Feb 2017 17:19:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from <553216793@qq.com>) id 1cf8BN-0006ss-D0 for pgsql-bugs@postgresql.org; Sat, 18 Feb 2017 16:48:27 +0000 Received: from smtpbg331.qq.com ([14.17.43.223]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from <553216793@qq.com>) id 1cf8BE-0002kV-Ef for pgsql-bugs@postgresql.org; Sat, 18 Feb 2017 16:48:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1487436484; bh=oOgtM5jDhQO8kHsMAmWnDcQn8a9giXt1ndDTQN72qtw=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ljEgUg5vuNYND600dYZencVszTQVdo8aT37Y3PVtPMVYbY8CV2iD8WCIMLK0hKeq8 3Dp6KpMbkOgChNvfmkmc3vDq7KaZNNCoKFaGiWF0nFMVTsMNC9A1CviRvpQ3Glo5TW EWVJuZfXj+zVVrcfJVNem30wT82KJcPRmQZJrL38= X-QQ-Spam: true X-QQ-mid: esmtp28t1487433850tqdwa6ldq Received: from IDEASPC (unknown [221.221.97.196]) by esmtp4.qq.com (ESMTP) with SMTP id 0 for ; Sun, 19 Feb 2017 00:04:09 +0800 (CST) X-QQ-SSF: 0000000000000040FL621F00000000C From: "Gao Yanxiao" <553216793@qq.com> To: Subject: BUG? select count(*) from table don't get value via PQgetvalue() function in libpq(C) Date: Sun, 19 Feb 2017 00:04:08 +0800 Message-ID: <000001d28a00$a3549c30$e9fdd490$@qq.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0001_01D28A43.B184D480" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdKJ+SroV8giF0MCTkOCIe4L5WcdBA== Content-Language: zh-cn X-QQ-SENDSIZE: 520 Feedback-ID: esmtp:qq.com:bgweb:bgweb133 X-Pg-Spam-Score: -1.8 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multipart message in MIME format. ------=_NextPart_000_0001_01D28A43.B184D480 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi, postgresql: First, my englist is not good. So I try to my best. Hope you can = understand me. =20 I programing a program use linux via C language. And I used libpq = connect to postgresql. Then I want calculate rows in a table. So I write PQexecparams() = perfrom sql statement: select count(*) from tablename.=20 Like this: PGresult *res; PQtrace(pgconn, stdout); res =3D PQexecParams(pgconn, "select count(*) from chat_connstate", = 0, NULL, NULL, NULL, NULL, 1); =20 Then I check res variable use=20 PQresultStatus(res) =3D=3D PGRES_TUPLES_OK that the status is successed. =20 So, I use PQgetvalue() function get the value, like this: Int result =3D *((int*)PQgetvalue(res, 0, 0)); Or=20 Long result =3D *((long*)PQgetvalue(res, 0, 0); But, the result variable value is zero, the I use PQfname(res, 0) and = PQfnumber(res, =E2=80=9Ccount=E2=80=9D) check status that output is = corrected. So, I change my code to: Int result =3D *((int*)PQgetvalue(res, 0, PQfnumber(res, = =E2=80=9Ccount=E2=80=9D); But, the result value still is zero. =20 I login postgresql use psql, then perfrom select count(*) from = tablename. The output is current, like: chatdb=3D# select count(*) from chat_connstate; count=20 ------- 1 (1 =E8=A1=8C=E8=AE=B0=E5=BD=95) =20 Then I perfrom =E2=80=9Cselect * from tablename=E2=80=9D in = PQexecparams, and get the values. The values is currect this time. =20 So, I test=20 Select sum(*) from tablename; Int result =3D *((int*)PQgetvalue(res, 0, 0); //the result = value is zero =20 Select avg(*) from tablename; Double result =3D *((double*)PQgetvalue(res, 0, 0); // the result = value is not zero, but still is not equal to psql output. =20 Finally, I have no ideas for new test way. Please help me. Thanks. =20 =20 output infomations use psql and PQtrace() function in gdb: (The system = and postgresql environment in the bottom.) =20 chatdb=3D# select * from chat_connstate; id | ip | port | connfd | = account | token | expires = | create_date =20 ----+------------------------------------------------+------+--------+---= ------+------------------------------------------+-----------------------= -----+---------------------------- 1 | 127.0.0.1 | 1 | 7 | = | 34a57ff275715c87235bf880f4c642d2539372fc | 2017-02-18 = 22:33:55.381506 | 2017-02-18 22:33:55.381506 (1 =E8=A1=8C=E8=AE=B0=E5=BD=95) =20 1. Select count(*) from chat_connstate =20 (gdb)=20 41 chat_psql_init_connstate(1); (gdb) s chat_psql_init_connstate (clear=3D1) at chat_psql.c:38 38 PQtrace(pgconn, stdout); (gdb) n 39 res =3D PQexecParams(pgconn, "select count(*) from = chat_connstate", (gdb) To backend> Msg P To backend> "" To backend> "select count(*) from chat_connstate" To backend (2#)> 0 To backend> Msg complete, length 44 To backend> Msg B To backend> "" To backend> "" To backend (2#)> 0 To backend (2#)> 0 To backend (2#)> 1 To backend (2#)> 1 To backend> Msg complete, length 15 To backend> Msg D To backend> P To backend> "" To backend> Msg complete, length 7 To backend> Msg E To backend> "" To backend (4#)> 0 To backend> Msg complete, length 10 To backend> Msg S To backend> Msg complete, length 5