Re: plpgsql: Checking status on a 'INSERT INTO ...'

Reinoud van Leeuwen <reinoud@xs4all.nl>

From: "Reinoud van Leeuwen" <reinoud@xs4all.nl>
To: <turbo@bayour.com>
Cc: <pgsql-hackers@postgresql.org>
Date: 2001-07-25T10:09:07Z
Lists: pgsql-hackers
> 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