plpgsql - Inserting DEFAULT Value.
| От | Vams |
|---|---|
| Тема | plpgsql - Inserting DEFAULT Value. |
| Дата | |
| Msg-id | 200406152129.29351.vmudrageda@charter.net обсуждение |
| Ответы |
Re: plpgsql - Inserting DEFAULT Value.
|
| Список | pgsql-general |
Hi all,
I need to protect a SERIAL column from having a value inserted into it (other
than the default sequence) and keep that value from being tampered with. So
I created a function which is called by a trigger. Unfortunately, I don't
know how to assign DEFAULT to the id column. Can anyone tell me how I can
fix my function or is there another easier way that doesn't need triggers or
functions? Here is what I got so far.
CREATE OR REPLACE FUNCTION id_protect()
RETURNS TRIGGER AS '
BEGIN
IF TG_OP = ''INSERT'' THEN
NEW.id := DEFAULT; -- here is the problem :(
RETURN NEW;
ELSIF TG_OP = ''UPDATE'' THEN
NEW.id := OLD.id;
RETURN NEW;
ELSE
RETURN NEW;
END IF;
END;
' LANGUAGE PLPGSQL;
Important point: I need this to be a generic function. I got multiple tables
that have a id column, each with their own unique sequences, and I want to
use the same function for all of them. So NEW.id := nextval('some_sequence')
can't work.
Thank you all,
Vams
В списке pgsql-general по дате отправления: