Re: Best Practice when Encounter Invalid Stored Procedure Parameters

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Yan Cheng Cheok <yccheok(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Best Practice when Encounter Invalid Stored Procedure Parameters
Date: 2010-01-12 06:33:07
Message-ID: 162867791001112233l5b7699cao712dfd737bbf8fd8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hello

2010/1/12 Yan Cheng Cheok <yccheok(at)yahoo(dot)com>:
> In c++, whenever we encounter an unexpected parameters, here is what we usually did :
>
> bool fun(int i) {
>    if (i < 0) {
>        return false;
>    }
> }
>
> void fun(int i) {
>    if (i < 0) {
>        throw std::exception("Invalid parameter");
>    }
> }
>
> void fun(int i) {
>    assert (i >= 0);
> }
>
> How about stored procedure? Now, I have the following stored procedure :
>
> CREATE OR REPLACE FUNCTION insert_unit(text[], text[])
>  RETURNS unit AS
> $BODY$DECLARE
>    _measurement_types ALIAS FOR $1;
>    _measurement_units ALIAS FOR $2;
>    _unit unit;
> BEGIN
>    IF array_upper(_measurement_values, 1) != array_upper(_measurement_units, 1) THEN
>        RAISE NOTICE 'What I should do here to return early???';
>    END IF;
>
> May I know what is the good practice to handle invalid parameters? I am using libpq to interface with PostgreSQL.

see RAISE EXCEPTION

http://www.depesz.com/index.php/2008/05/14/waiting-for-84-plpgsql-raise/

Regards
Pavel Stehule

>
> Thanks and Regards
> Yan Cheng CHEOK
>
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Leigh Dyer 2010-01-12 06:39:12 Backup strategies with significant bytea data
Previous Message Pavel Stehule 2010-01-12 06:30:03 Re: transaction logging in the form of SQL statements