pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jayadevan M <Jayadevan.Maymala@ibsplc.com>
To: Snyder, James <jsnyde07@harris.com>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-sql-owner@postgresql.org
Subject: Re: SQL syntax rowcount value as an extra column in the result set
Date: Fri, 26 Mar 2010 09:05:00 +0530
Message-ID: <OF5A2D0504.FE37F1EE-ON652576F2.00139075-652576F2.00138CC0@LocalDomain> (raw)
In-Reply-To: <594D625E4784AD4EA9D423E292BE6725489FD1@mlbe2k10.cs.myharris.net>
References: <594D625E4784AD4EA9D423E292BE6725489FD1@mlbe2k10.cs.myharris.net>

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" <jsnyde07@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-owner@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." 

view thread (9+ messages)  latest in thread

Message-ID: <OF5A2D0504.FE37F1EE-ON652576F2.00139075-652576F2.00138CC0@LocalDomain>
Permalink:  ../OF5A2D0504.FE37F1EE-ON652576F2.00139075-652576F2.00138CC0@LocalDomain/
Also on:    postgresql.org/message-id/OF5A2D0504.FE37F1EE-ON652576F2.00139075-652576F2.00138CC0@LocalDomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: Jayadevan.Maymala@ibsplc.com, jsnyde07@harris.com, pgsql-sql-owner@postgresql.org
  Subject: Re: SQL syntax rowcount value as an extra column in the result set
  In-Reply-To: <OF5A2D0504.FE37F1EE-ON652576F2.00139075-652576F2.00138CC0@LocalDomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox