Re: [GENERAL] Getting the result of a query using COUNT(*)

Started by Yury Donover 25 years ago3 messagesgeneral
Jump to latest
#1Yury Don
yura@vpcit.ru

Jackson Ching wrote:

Hi,

I'm using JSDK 2.0 and IBM JDK 1.3 on RedHat Linux 6.2

As i test my servlet, I got errors saying count(*) column not found in a query like this

SELECT COUNT(*) FROM MyTable

in my rs.getint("COUNT(*)"); in oracle it works fine, in postgresql it doesn't. how should i handle aggregate functions in SQL then?

Thanks

Jackson

What version of rostgres do you use?
SELECT COUNT(*) FROM MyTable works pretty well in postgres 6.5.1 and
later.
Perhaps problem is in java?

--
Sincerely yours,
Yury

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Yury Don (#1)
Re: Getting the result of a query using COUNT(*)

"Jackson Ching" <jching@imvi.com.ph> writes:

SELECT COUNT(*) FROM MyTable

in my rs.getint("COUNT(*)");

Offhand I'd guess that the returned column heading is "count" not
"COUNT(*)". Use an AS clause if you want to be sure about the
column heading of a SELECT result...

regards, tom lane

#3Alexandru COSTIN
acostin@rds.ro
In reply to: Yury Don (#1)
Re: Re: [GENERAL] Getting the result of a query using COUNT(*)

Hello
Try this way:
SELECT COUNT(*) as no FROM MyTable
rs.getint("no");
Or
SELECT COUNT(*) FROM MyTable
rs.getInt(0); (or (1))
alexander

Jackson Ching wrote:

Hi,

I'm using JSDK 2.0 and IBM JDK 1.3 on RedHat Linux 6.2

As i test my servlet, I got errors saying count(*) column not

found in a query like this

SELECT COUNT(*) FROM MyTable

in my rs.getint("COUNT(*)"); in oracle it works fine, in

postgresql it doesn't. how should i handle aggregate functions in SQL then?

Show quoted text

Thanks

Jackson

What version of rostgres do you use?
SELECT COUNT(*) FROM MyTable works pretty well in postgres 6.5.1 and
later.
Perhaps problem is in java?

--
Sincerely yours,
Yury