From: | Sergey Konoplev <gray(dot)ru(at)gmail(dot)com> |
---|---|
To: | Sergey Gigoyan <sergey(dot)gigoyan(at)gmail(dot)com> |
Cc: | pgsql-novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Row Count |
Date: | 2013-02-12 08:07:21 |
Message-ID: | CAL_0b1tZ50rp8ms5LOiS8wnDSXpCUCJ22JKxKT=6M5Yp=u_NVg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Mon, Feb 11, 2013 at 11:05 PM, Sergey Gigoyan
<sergey(dot)gigoyan(at)gmail(dot)com> wrote:
> How can I get selected row count in one statement?
Usually it is immediately available after statement execution without
additional query.
For example in PL/PgSQL you can use GET DIAGNOSTICS straight after your SELECT:
SELECT INTO _id, _name, _address id, name, address
FROM users WHERE name <> 'examplename';
GET DIAGNOSTICS _row_count = ROW_COUNT;
In external languages like Perl:
$sth = $dbh->prepare(
"select id, name, address, rowcount as rowcount".
"from users where name<>'examplename'");
$row_count = $sth->execute(...);
> For example, I can do that by two select statements
>
> select id, name, addrress, (select count(*) from(select id
> from
> users
> where
> name<>'examplename')
> from users
> where name<>'examplename'
>
> or
>
> declare rowcount integer
> ...............
> rowcount:=select count(*) from(select id
> from users
> where name<>'examplename')
> as rst
>
> select id, name, address, rowcount as rowcount
> from users
> where name<>'examplename'
>
--
Sergey Konoplev
Database and Software Architect
http://www.linkedin.com/in/grayhemp
Phones:
USA +1 415 867 9984
Russia, Moscow +7 901 903 0499
Russia, Krasnodar +7 988 888 1979
Skype: gray-hemp
Jabber: gray(dot)ru(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Kellerer | 2013-02-12 08:18:12 | Re: Row Count |
Previous Message | Andreas Kretschmer | 2013-02-12 08:03:02 | Re: Row Count |