Re: Read-only column

Поиск
Список
Период
Сортировка
От Chris Travers
Тема Re: Read-only column
Дата
Msg-id 1071326902.2212.841.camel@localhost.localdomain
обсуждение исходный текст
Ответ на Re: Read-only column  (Doug McNaught <doug@mcnaught.org>)
Ответы Re: Read-only column
Список pgsql-general
Or, depending if you just want to ignore updates to that field (not
always best, but possible, similar to a view).

CREATE OR REPLACE FUNCTION block_col()
RETURNS TRIGGER AS '
    BEGIN
        NEW.ts_field := OLD.ts_field;
        RETURN NEW;
    END;
' LANGUAGE PLPGSQL;

In place of the assignment, you could also test for inequality and raise
an error as Doug suggested:
        IF NEW.ts_field != OLD.ts_field THEN
            RAISE EXCEPTION ''Update to % Not Permitted'',
                ts_field
        END IF;
Best Wishes,
Chris Travers


On Sat, 2003-12-13 at 23:24, Doug McNaught wrote:
> Claudio Succa <claudio.succa.ml@pertel.it> writes:
>
> > (Not to reinvent the wheel, do you know where I could find a suitable
> > function to use in the trigger?)
>
> No, but it should be pretty trivial to write.  Just set up a BEFORE
> UPDATE trigger that compares OLD.ts_field against NEW.ts_field and
> does a RAISE ERROR if they're different.  The PL/pgSQL docs have a few
> decent examples of how to write a trigger function.
>
> -Doug
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>


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

Предыдущее
От: Doug McNaught
Дата:
Сообщение: Re: Read-only column
Следующее
От: Josué Maldonado
Дата:
Сообщение: Why is postgres an ORDMS