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

From: "Reinoud van Leeuwen" <reinoud(at)xs4all(dot)nl>
To: <turbo(at)bayour(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: plpgsql: Checking status on a 'INSERT INTO ...'
Date: 2001-07-25 10:09:07
Message-ID: 42673.194.109.0.126.996055747.squirrel@webmail.xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Gunnar Rønning 2001-07-25 12:49:18 Re: Re: Storing XML in PostgreSQL
Previous Message Turbo Fredriksson 2001-07-25 09:59:21 plpgsql: Checking status on a 'INSERT INTO ...'