Re: dynmic column names inside trigger?
| От | Bart Degryse |
|---|---|
| Тема | Re: dynmic column names inside trigger? |
| Дата | |
| Msg-id | 47459C32.A3DD.0030.0@indicator.be обсуждение исходный текст |
| Ответ на | Re: dynmic column names inside trigger? (Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>) |
| Список | pgsql-sql |
I don't really see how you could test a non-existing column. Here
> if old.story is not null and new.story != old.story then
> new.story = sanitize_text(new.story);
you would always use fields from OLD and NEW otherwise you can't even create the trigger.
> new.story = sanitize_text(new.story);
you would always use fields from OLD and NEW otherwise you can't even create the trigger.
If a table has 3 fields (field1, field2 and field3) then why would you create a trigger in which
you do something with field4. I haven't tried (because it seems so absurd) but I expect
PG to refuse to create such a trigger.
>>> Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org> 2007-11-22 14:54 >>>
On Wed, Nov 21, 2007 at 09:14:14AM +0100, Bart Degryse wrote:
> I would do something like this (not tested, but conceptually working):
Hello,
> BEGIN
> if old.story is not null and new.story != old.story then
> new.story = sanitize_text(new.story);
> end if;
> --checks on other field can be included here, eg
> if old.otherfield is not null and new.otherfield != old.otherfield then
> new.otherfield = sanitize_text(new.otherfield);
> end if;
But if I test a non-existent column for not being null I will have an
exception, no?
Otherwise this is a nice way of doing it.
Thanks,
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
В списке pgsql-sql по дате отправления: