Thread: COMMAND_OK for PL/pgSQL?

COMMAND_OK for PL/pgSQL?

From
Ben
Date:
I'm just getting into writting stored procs with PL/pgSQL, and I'm having
a hard time finding a way to check the status of my commands. For
instance, I see that after an insert, I can get the RESULT_OID - but I'm
not sure this is a good way to check if the insert happened correctly and
didn't violate any constraints. If it is, how do I check that the oid
returned is valid?



Re: COMMAND_OK for PL/pgSQL?

From
Darko Prenosil
Date:
On Saturday 26 October 2002 15:07, Ben wrote:
> I'm just getting into writting stored procs with PL/pgSQL, and I'm having
> a hard time finding a way to check the status of my commands. For
> instance, I see that after an insert, I can get the RESULT_OID - but I'm
> not sure this is a good way to check if the insert happened correctly and
> didn't violate any constraints. If it is, how do I check that the oid
> returned is valid?
>

    I think, when referential integrity is violated, exception is raised
automatically, transaction that PL/PSQL started is rolled back and
exit from function occurs.
    If you check your data for example in "TRIGGER", and you
find out that the data is invalid, all you have to do is "RAISE EXCEPTION".
So if the insert is invalid, there is no need to check it again, because the
line after that "INSERT" statement will never be executed.
It is similar to THROW in C++, only there is only one "CATCH" statement,
handled by server.

>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


Re: COMMAND_OK for PL/pgSQL?

From
Ben
Date:
Hmmm.... I guess what I was hoping was to be able to return specific error
codes in case the insert failed.

On Sun, 27 Oct 2002, Darko Prenosil wrote:

> On Saturday 26 October 2002 15:07, Ben wrote:
> > I'm just getting into writting stored procs with PL/pgSQL, and I'm having
> > a hard time finding a way to check the status of my commands. For
> > instance, I see that after an insert, I can get the RESULT_OID - but I'm
> > not sure this is a good way to check if the insert happened correctly and
> > didn't violate any constraints. If it is, how do I check that the oid
> > returned is valid?
> >
>
>     I think, when referential integrity is violated, exception is raised
> automatically, transaction that PL/PSQL started is rolled back and
> exit from function occurs.
>     If you check your data for example in "TRIGGER", and you
> find out that the data is invalid, all you have to do is "RAISE EXCEPTION".
> So if the insert is invalid, there is no need to check it again, because the
> line after that "INSERT" statement will never be executed.
> It is similar to THROW in C++, only there is only one "CATCH" statement,
> handled by server.
>
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> >     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>