Hi,
Is this what you are trying to do?
postgres=# select * from (select count(*) from people ) p, (select 
firstname from people)p2;
 count | firstname
-------+-----------
     5 | Mary
     5 | Mary
     5 | John
     5 | John
     5 | Jacob
(5 rows)
I do not know about the performance impact of such a query (cartesian 
join)
Regards,
Jayadevan




From:   "Snyder, James" <jsnyd...@harris.com>
To:     <pgsql-sql@postgresql.org>
Date:   26/03/2010 03:21
Subject:        [SQL] SQL syntax rowcount value as an extra column in the 
result set
Sent by:        pgsql-sql-ow...@postgresql.org



Hello
I’m using PostgreSQL (8.4.701) and Java (jdbc, 
postgresql-8.4-701.jdbc4.jar) to connect to the database.
My question is: what is the SQL syntax for PostgreSQL to achieve the 
following:
I want to receive the rowcount along with the rest of a result set. For 
example, let’s say the following query returns
select first_name from people;
first_name
=========
Mary
Sue
Joe

and the following query returns the value 
select count(*)as ROWCOUNT from people;
ROWCOUNT
==========
3
3
What I’m looking for is the output as
ROWCOUNT ,  first_name
=====================
3 , Mary
3 , Sue
3 , Joe
so I can use JDBC (snip-it) as follows:
resultSet.getInt(“ROWCOUNT”)
resultSet.getString(“first_name”)
On a side note, Oracle allows the following syntax to achieve the above:
select count(*) over () as ROWCOUNT , first_name from people
Thanks,Jim

DISCLAIMER:   "The information in this e-mail and any attachment is intended 
only for the person to whom it is addressed and may contain confidential and/or 
privileged material. If you have received this e-mail in error, kindly contact 
the sender and destroy all copies of the original communication. IBS makes no 
warranty, express or implied, nor guarantees the accuracy, adequacy or 
completeness of the information contained in this email or any attachment and 
is not liable for any errors, defects, omissions, viruses or for resultant loss 
or damage, if any, direct or indirect." 

Reply via email to