pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
rowcount function in postgres???
4+ messages / 4 participants
[nested] [flat]

* rowcount function in postgres???
@ 2007-04-07 17:33 Karthikeyan Sundaram <skarthi98@hotmail.com>
  2007-04-07 17:51 ` Re: rowcount function in postgres??? Michael Fuhr <mike@fuhr.org>
  2007-04-07 17:54 ` Re: [SQL] rowcount function in postgres??? Rodrigo De León <rdeleonp@gmail.com>
  2007-04-07 18:58 ` Re: rowcount function in postgres??? Uwe C. Schroeder <uwe@oss4u.com>
  0 siblings, 3 replies; 4+ messages in thread

From: Karthikeyan Sundaram @ 2007-04-07 17:33 UTC (permalink / raw)
  To: postgres admin <pgsql-admin@postgresql.org>; pgsql-sql


Hi,
 
   I am using 8.1.0 postgres and trying to write a plpgsql block.  In that I am inserting a row.  I want to check to see if the row has been inserted or not.
 
  In oracle we can say like this
 
   begin
     insert into table_a values (1);
     if sql%rowcount > 0
     then
       dbms.output.put_line('rows inserted');
     else 
       dbms.output.put_line('rows not inserted');
    end if;
end;
 
Is there something equal to sql%rowcount in postgres?   Please help.
 
Regards
skarthi
 
_________________________________________________________________
It’s tax season, make sure to follow these few simple tips 
http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.aspx?icid=WLMartagline=

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: rowcount function in postgres???
  2007-04-07 17:33 rowcount function in postgres??? Karthikeyan Sundaram <skarthi98@hotmail.com>
@ 2007-04-07 17:51 ` Michael Fuhr <mike@fuhr.org>
  2 siblings, 0 replies; 4+ messages in thread

From: Michael Fuhr @ 2007-04-07 17:51 UTC (permalink / raw)
  To: Karthikeyan Sundaram <skarthi98@hotmail.com>; +Cc: pgsql-sql

On Sat, Apr 07, 2007 at 10:33:19AM -0700, Karthikeyan Sundaram wrote:
> I am using 8.1.0 postgres and trying to write a plpgsql block.

8.1.8 is the latest version in that branch.  Read the Release Notes
for each minor release to see what bug fixes you're missing.

http://www.postgresql.org/docs/8.1/interactive/release.html

> In that I am inserting a row.  I want to check to see if the row
> has been inserted or not.

See "Obtaining the Result Status" and "Trapping Errors" in the
PL/pgSQL documentation.

http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTIC...
http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPIN...

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] rowcount function in postgres???
  2007-04-07 17:33 rowcount function in postgres??? Karthikeyan Sundaram <skarthi98@hotmail.com>
@ 2007-04-07 17:54 ` Rodrigo De León <rdeleonp@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Rodrigo De León @ 2007-04-07 17:54 UTC (permalink / raw)
  To: pgsql-admin@postgresql.org; pgsql-sql; +Cc: Karthikeyan Sundaram <skarthi98@hotmail.com>

On 4/7/07, Karthikeyan Sundaram <skarthi98@hotmail.com> wrote:
>
>  Hi,
>
>     I am using 8.1.0 postgres and trying to write a plpgsql block.  In that
> I am inserting a row.  I want to check to see if the row has been inserted
> or not.
>
>    In oracle we can say like this
>
>     begin
>       insert into table_a values (1);
>       if sql%rowcount > 0
>       then
>         dbms.output.put_line('rows inserted');
>       else
>         dbms.output.put_line('rows not inserted');
>      end if;
>  end;
>
>  Is there something equal to sql%rowcount in postgres?   Please help.
>
>  Regards
>  skarthi

Maybe:

http://www.postgresql.org/docs/8.2/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: rowcount function in postgres???
  2007-04-07 17:33 rowcount function in postgres??? Karthikeyan Sundaram <skarthi98@hotmail.com>
@ 2007-04-07 18:58 ` Uwe C. Schroeder <uwe@oss4u.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Uwe C. Schroeder @ 2007-04-07 18:58 UTC (permalink / raw)
  To: pgsql-admin@postgresql.org; +Cc: Karthikeyan Sundaram <skarthi98@hotmail.com>; pgsql-sql


you could simply write

insert into table_a values (1);
 if found then
       dbms.output.put_line('rows inserted');
 else
       dbms.output.put_line('rows not inserted');
  end if;


If you really need the number of records inserted (found will be true if at 
least one record as affected), you can get that with

GET DIAGNOSTICS num_rows = ROW_COUNT;
and then do the if on the variable num_rows.

Hope that helps

UC


On Saturday 07 April 2007 10:33, Karthikeyan Sundaram wrote:
> Hi,
>
>    I am using 8.1.0 postgres and trying to write a plpgsql block.  In that
> I am inserting a row.  I want to check to see if the row has been inserted
> or not.
>
>   In oracle we can say like this
>
>    begin
>      insert into table_a values (1);
>      if sql%rowcount > 0
>      then
>        dbms.output.put_line('rows inserted');
>      else
>        dbms.output.put_line('rows not inserted');
>     end if;
> end;
>
> Is there something equal to sql%rowcount in postgres?   Please help.
>
> Regards
> skarthi
>
> _________________________________________________________________
> It’s tax season, make sure to follow these few simple tips
> http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.
>aspx?icid=WLMartagline

-- 
	UC

--
Open Source Solutions 4U, LLC	1618 Kelly St
Phone:  +1 707 568 3056		Santa Rosa, CA 95401
Cell:   +1 650 302 2405		United States
Fax:    +1 707 568 6416



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2007-04-07 18:58 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-04-07 17:33 rowcount function in postgres??? Karthikeyan Sundaram <skarthi98@hotmail.com>
2007-04-07 17:51 ` Michael Fuhr <mike@fuhr.org>
2007-04-07 17:54 ` Rodrigo De León <rdeleonp@gmail.com>
2007-04-07 18:58 ` Uwe C. Schroeder <uwe@oss4u.com>

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