I'm porting some stored procedures from a MSSQL server, and thought
I'd use PL/pgSQL.

The original code is checking the insert with the line:

        if (@@Error != 0)

How do I do the same thing in PL/pgSQL?

-- 
 Turbo     __ _     Debian GNU     Unix _IS_ user friendly - it's just 
 ^^^^^    / /(_)_ __  _   ___  __  selective about who its friends are 
         / / | | '_ \| | | \ \/ /   Debian Certified Linux Developer  
  _ /// / /__| | | | | |_| |>  <  Turbo Fredriksson   turbo@tripnet.se
  \\\/  \____/_|_| |_|\__,_/_/\_\ Stockholm/Sweden

explosion ammonium ammunition iodine strategic Rule Psix NORAD FBI
fissionable Treasury cryptographic killed AK-47 Nazi Waco, Texas
[See http://www.aclu.org/echelonwatch/index.html for more about this]

25 Jul 2001 11:59:21 +0200
Turbo Fredriksson <turbo@bayour.com>
plpgsql: Checking status on a 'INSERT INTO ...'
> I'm porting some stored procedures from a MSSQL server, and thought I'd
> use PL/pgSQL.
> 
> The original code is checking the insert with the line:
> 
>        if (@@Error != 0)

You might want to use something like:

SELECT INTO variable_name *
  FROM table
 WHERE field = some_value;

IF FOUND THEN
  somevar := variable_name.fieldname ;
ELSE
  RAISE EXCEPTION ''ERROR blah blah'';
END IF;

And you also want to look into the @@rowcount:

GET DIAGNOSTICS v_rowcount = ROW_COUNT ;

Reinoud


Wed, 25 Jul 2001 12:09:07 +0200 (CEST)
"Reinoud van Leeuwen" <reinoud@xs4all.nl>
Re: plpgsql: Checking status on a 'INSERT INTO ...'