Обсуждение: rowcount function in postgres???

Поиск
Список
Период
Сортировка

rowcount function in postgres???

От
Karthikeyan Sundaram
Дата:
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 Check it out!

Re: [SQL] rowcount function in postgres???

От
"Rodrigo De León"
Дата:
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

Re: rowcount function in postgres???

От
"Uwe C. Schroeder"
Дата:
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