Best Practice when Encounter Invalid Stored Procedure Parameters

Поиск
Список
Период
Сортировка
От Yan Cheng Cheok
Тема Best Practice when Encounter Invalid Stored Procedure Parameters
Дата
Msg-id 837103.5437.qm@web65715.mail.ac4.yahoo.com
обсуждение исходный текст
Ответы Re: Best Practice when Encounter Invalid Stored Procedure Parameters  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-general
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.

Thanks and Regards
Yan Cheng CHEOK





В списке pgsql-general по дате отправления:

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: replication from multiple "master" servers to a single read-only slave
Следующее
От: Omar Mehmood
Дата:
Сообщение: transaction logging in the form of SQL statements