Re: plpgsql: Checking status on a 'INSERT INTO ...' - Mailing list pgsql-hackers

From Reinoud van Leeuwen
Subject Re: plpgsql: Checking status on a 'INSERT INTO ...'
Date
Msg-id 42673.194.109.0.126.996055747.squirrel@webmail.xs4all.nl
Whole thread Raw
In response to plpgsql: Checking status on a 'INSERT INTO ...'  (Turbo Fredriksson <turbo@bayour.com>)
List 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 tableWHERE 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



pgsql-hackers by date:

Previous
From: Turbo Fredriksson
Date:
Subject: plpgsql: Checking status on a 'INSERT INTO ...'
Next
From: Hannu Krosing
Date:
Subject: Has anybody gop PL/Python to work on linux/pg7.1.2 ?