Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Как в триггере узнать его таблицу? / 4 сообщений из 4, страница 1 из 1
16.11.2006, 12:33
    #34132869
DDT
DDT
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как в триггере узнать его таблицу?
Привет.

2 пути решения - 2 вопроса:

1. Можно ли внутри триггера узнать имя таблицы, в которой он был запущен?
Что-то типа parent_yable_name()

2. Есть идея через системные представления найти OID триггера, а по нему найти таблицу, тогда как узнать OID или имя триггера?

Спасибо.
...
Рейтинг: 0 / 0
16.11.2006, 12:50
    #34132976
Misha Tyurin
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как в триггере узнать его таблицу?
Для PL/pgSQL вот такой есть списочек: "

When a PL/pgSQL function is called as a trigger, several special variables are created automatically in the top-level block. They are:

NEW

Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level triggers. This variable is NULL in statement-level triggers.
OLD

Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in row-level triggers. This variable is NULL in statement-level triggers.
TG_NAME

Data type name; variable that contains the name of the trigger actually fired.
TG_WHEN

Data type text; a string of either BEFORE or AFTER depending on the trigger's definition.
TG_LEVEL

Data type text; a string of either ROW or STATEMENT depending on the trigger's definition.
TG_OP

Data type text; a string of INSERT, UPDATE, or DELETE telling for which operation the trigger was fired.
TG_RELID

Data type oid; the object ID of the table that caused the trigger invocation.
TG_RELNAME


Data type name; the name of the table that caused the trigger invocation.
TG_NARGS

Data type integer; the number of arguments given to the trigger procedure in the CREATE TRIGGER statement.
TG_ARGV[]

Data type array of text; the arguments from the CREATE TRIGGER statement. The index counts from 0. Invalid indices (less than 0 or greater than or equal to tg_nargs) result in a null value.

"
Вот тут (http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.html) всё это есть и ещё много чего.
...
Рейтинг: 0 / 0
16.11.2006, 13:09
    #34133061
Misha Tyurin
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как в триггере узнать его таблицу?
Блин, список неправлильно запостился, вот так красивее:

NEW
Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level triggers. This variable is NULL in statement-level triggers.

OLD
Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in row-level triggers. This variable is NULL in statement-level triggers.

TG_NAME
Data type name; variable that contains the name of the trigger actually fired.

TG_WHEN
Data type text; a string of either BEFORE or AFTER depending on the trigger's definition.

TG_LEVEL
Data type text; a string of either ROW or STATEMENT depending on the trigger's definition.

TG_OP
Data type text; a string of INSERT, UPDATE, or DELETE telling for which operation the trigger was fired.

TG_RELID
Data type oid; the object ID of the table that caused the trigger invocation.

TG_RELNAME
Data type name; the name of the table that caused the trigger invocation.


TG_NARGS
Data type integer; the number of arguments given to the trigger procedure in the CREATE TRIGGER statement.

TG_ARGV[]
Data type array of text; the arguments from the CREATE TRIGGER statement. The index counts from 0. Invalid indices (less than 0 or greater than or equal to tg_nargs) result in a null value.

(Вот тут (http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.html) всё это есть и ещё много чего.)
...
Рейтинг: 0 / 0
16.11.2006, 13:12
    #34133076
DDT
DDT
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как в триггере узнать его таблицу?
Спасибо. Полегчало :)
...
Рейтинг: 0 / 0
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Как в триггере узнать его таблицу? / 4 сообщений из 4, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]