Обсуждение: Executing SQL commands via triggers without the use of procedures

Поиск
Список
Период
Сортировка

Executing SQL commands via triggers without the use of procedures

От
"Susan Hoddinott"
Дата:
Hello,
 
Having scoured the relevant documentation I cannot find anything which indicates how I simply create a database trigger to insert into a second table after insert on a first table, without the use of a procedure.  As I do not want return values etc. this seems like overkill.  Is it possible to create a trigger which executes SQL directly without the need to create a procedure?  If so, what is the syntax?
 
Regards
Вложения

Re: Executing SQL commands via triggers without the use of

От
Stephan Szabo
Дата:
On Fri, 28 Feb 2003, Susan Hoddinott wrote:

> Having scoured the relevant documentation I cannot find anything which
> indicates how I simply create a database trigger to insert into a
> second table after insert on a first table, without the use of a
> procedure.  As I do not want return values etc. this seems like
> overkill.  Is it possible to create a trigger which executes SQL
> directly without the need to create a procedure?  If so, what is the
> syntax?

Not really... You'll need to wrap it in a simple function.




Re: Executing SQL commands via triggers without the use of procedures

От
Jeff Eckermann
Дата:
--- Susan Hoddinott <susan@perth.dialix.com.au> wrote:
> Hello,
> 
> Having scoured the relevant documentation I cannot
> find anything which indicates how I simply create a
> database trigger to insert into a second table after
> insert on a first table, without the use of a
> procedure.  As I do not want return values etc. this
> seems like overkill.  Is it possible to create a
> trigger which executes SQL directly without the need
> to create a procedure?  If so, what is the syntax?
> 

You don't need to worry about those return values;
nothing will be returned to your application from a
trigger function.  AFAICT the only difference between
PostgreSQL and other DBMSs is that (at least some)
others put the procedural logic inside the "create
trigger" statement, whereas PostgreSQL puts it in a
separate function.  You need to think about this only
at statement creation time; otherwise everything works
just the same.  One tip: always use the "create or
replace function" syntax, to avoid having your trigger
become confused if you change your function definition.

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/


Re: Executing SQL commands via triggers without the use of procedures

От
Oleg Samoylov
Дата:
You can use rules for this purpose.
-- 
Olleg Samoylov



Re: Executing SQL commands via triggers without the use of procedures

От
"fabio"
Дата:
>
> Having scoured the relevant documentation I cannot find anything which indi=
> cates how I simply create a database trigger to insert into a second table =
> after insert on a first table, without the use of a procedure.  As I do not=
>  want return values etc. this seems like overkill.  Is it possible to creat=
> e a trigger which executes SQL directly without the need to create a proced=
> ure?  If so, what is the syntax?
>

hello! I had the same problem, is possible to solve it with a rules but
depend. In my db i used a trigger because,i have multiple insert in
cascade and the rules dont handle this

manual for trigger procedure:
http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=plpgsql-trigger.html

trigger vs rules
http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=rules-triggers.html

fabio