Re: [NOVICE] FUNCTION, TRIGGER and best practices

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: [NOVICE] FUNCTION, TRIGGER and best practices
Дата
Msg-id 200412162143.32610.josh@agliodbs.com
обсуждение исходный текст
Список pgsql-sql
Keith,

> Can triggers and functions have the same name?

Yes.

> Is this a good practice?

It can be.   If the function does nothing but power the trigger, sure.   Or
you can use prefixes or suffixes to distinguish them.  For example, if you
had an audit trigger on the companies table, you might call the function
audit_companies_tf, the trigger audit_companies_tg.

> Where should the function and trigger be stored?

Um, in the database?

> In the same schema as the table they are connected to?

I'm not sure you CAN put the trigger in a different schema from the table.
It's a dependant object.

> I will now be attempting to expand this function to move data from two
> source tables to four or more target tables.  (Different source columns go
> to different tables.)  Is it possible to do a transaction/commit/rollback
> inside a function that is driven by a trigger so that if any portion of the
> transfer fails it is all rolled back?

Well, if any portion of a trigger fails, everything is rolled back; so is the
insert, for a before trigger.  So that might be the way to handle the
double-trigger situation .... except they'll be in two different tables, yes?
So that'll require an explicit transaction wrapping the two inserts.

--
Josh Berkus
Aglio Database Solutions
San Francisco

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

Предыдущее
От: Christopher Browne
Дата:
Сообщение: Re: plpgsql.. SELECT INTO ... WHERE FIELD LIKE
Следующее
От: "Richard Sydney-Smith"
Дата:
Сообщение: Table History