pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jayadevan M <Jayadevan.Maymala@ibsplc.com>
To: A. Kretschmer <andreas.kretschmer@schollglas.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 12:26:54 +0530
Message-ID: <OF3566EE01.958C8348-ON652576F2.002579A1-652576F2.002608F3@LocalDomain> (raw)
In-Reply-To: <20100326062350.GA6817@a-kretschmer.de>
References: <594D625E4784AD4EA9D423E292BE6725489FD1@mlbe2k10.cs.myharris.net>
	<hogm4r$gh6$1@dough.gmane.org>
	<OFA0B1E010.BE09B175-ON652576F2.00143421-652576F2.0014316E@LocalDomain>
	<20100326062350.GA6817@a-kretschmer.de>

Hi,
>It works, but you should use a recent version:

>test=*# select count(1) over (), i from foo;
> count | i
>-------+----
>     8 |  1
>     8 |  2
>     8 |  3
>     8 |  6
>     8 |  7
>     8 |  9
>     8 | 13
>     8 | 14
>(8 rows)

> test=*# select version();
>                                                version
> 
--------------------------------------------------------------------------------------------------------
>  PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.3.real
> (Debian 4.3.2-1.1) 4.3.2, 64-bit
> (1 row)

Thank you for setting that right. Apologies for not checking version.
Is this approach better compared to 
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)
This gives me
postgres=# explain  select * from (select count(*) from people )as p, 
(select firstname from people)p2;
                             QUERY PLAN
---------------------------------------------------------------------
 Nested Loop  (cost=14.00..30.42 rows=320 width=226)
   ->  Aggregate  (cost=14.00..14.01 rows=1 width=0)
         ->  Seq Scan on people  (cost=0.00..13.20 rows=320 width=0)
   ->  Seq Scan on people  (cost=0.00..13.20 rows=320 width=218)

Since I don't have 8.4, I am not in a position to do explain on that 
version. My guess - over () will be better. My query does sequential 
scans/nested loop...(if there are no indexes)

Regards,
Regards,
Jayadevan
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: <OF3566EE01.958C8348-ON652576F2.002579A1-652576F2.002608F3@LocalDomain>
Permalink:  ../OF3566EE01.958C8348-ON652576F2.002579A1-652576F2.002608F3@LocalDomain/
Also on:    postgresql.org/message-id/OF3566EE01.958C8348-ON652576F2.002579A1-652576F2.002608F3@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, andreas.kretschmer@schollglas.com, pgsql-sql-owner@postgresql.org
  Subject: Re: SQL syntax rowcount value as an extra column in the result set
  In-Reply-To: <OF3566EE01.958C8348-ON652576F2.002579A1-652576F2.002608F3@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