pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Question regarding triggers
6+ messages / 4 participants
[nested] [flat]

* Question regarding triggers
@ 2003-10-20 13:00  Dmitri Fuerle <ffo2lp@yahoo.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Dmitri Fuerle @ 2003-10-20 13:00 UTC (permalink / raw)
  To: pgsql-sql

 
   I'm writing a trigger but running into problems.  My problem is that I can not determine anyway to tell what fields are in the *new* record.  Without knowing what fields are there I get runtime errors if that's not what is being updated example:
 
CREATE FUNCTION "public"."check_shipment" () RETURNS trigger AS'
begin
    If new.shipment_type_id = 4 then
        --do something
    end if;
    return new;
end;
 
in the above example everything works if shipment_type_id is being updated.  If it is not I will receive a run-time error because shipment_type_id is not part of the record new.
 
Please help,
Dmitri
 



---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Question regarding triggers
@ 2003-10-20 13:22  achill@matrix.gatewaynet.com
  parent: Dmitri Fuerle <ffo2lp@yahoo.com>
  0 siblings, 1 reply; 6+ messages in thread

From: achill@matrix.gatewaynet.com @ 2003-10-20 13:22 UTC (permalink / raw)
  To: Dmitri Fuerle <ffo2lp@yahoo.com>; +Cc: pgsql-sql

Why dont you try to write your trigger in C?

On Mon, 20 Oct 2003, Dmitri Fuerle wrote:

>  
>    I'm writing a trigger but running into problems.  My problem is that I can not determine anyway to tell what fields are in the *new* record.  Without knowing what fields are there I get runtime errors if that's not what is being updated example:
>  
> CREATE FUNCTION "public"."check_shipment" () RETURNS trigger AS'
> begin
>     If new.shipment_type_id = 4 then
>         --do something
>     end if;
>     return new;
> end;
>  
> in the above example everything works if shipment_type_id is being updated.  If it is not I will receive a run-time error because shipment_type_id is not part of the record new.
>  
> Please help,
> Dmitri
>  
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search

-- 
-Achilleus




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Question regarding triggers
@ 2003-10-20 13:31  A.Bhuvaneswaran <bhuvan@symonds.net>
  parent: achill@matrix.gatewaynet.com
  0 siblings, 3 replies; 6+ messages in thread

From: A.Bhuvaneswaran @ 2003-10-20 13:31 UTC (permalink / raw)
  To: achill@matrix.gatewaynet.com; +Cc: Dmitri Fuerle <ffo2lp@yahoo.com>; pgsql-sql

> Why dont you try to write your trigger in C?

Hi, one cannot write triggered procedures in C. Currently, it can only be
written in plpsgql.

> > CREATE FUNCTION "public"."check_shipment" () RETURNS trigger AS'
> > begin
> >     If new.shipment_type_id = 4 then
> >         --do something
> >     end if;
> >     return new;
> > end;
> >  in the above example everything works if shipment_type_id is being
> > updated.  If it is not I will receive a run-time error because
> > shipment_type_id is not part of the record new.

All the fields of updated record must available in NEW variable.  Refer
the manual for details. Forward your sql & run-time error for further 
assistance.

regards,
bhuvaneswaran





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Question regarding triggers
@ 2003-10-20 13:48  Tom Lane <tgl@sss.pgh.pa.us>
  parent: A.Bhuvaneswaran <bhuvan@symonds.net>
  2 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2003-10-20 13:48 UTC (permalink / raw)
  To: A.Bhuvaneswaran <bhuvan@symonds.net>; +Cc: achill@matrix.gatewaynet.com, Dmitri Fuerle <ffo2lp@yahoo.com>; pgsql-sql

"A.Bhuvaneswaran" <bhuvan@symonds.net> writes:
>> Why dont you try to write your trigger in C?

> Hi, one cannot write triggered procedures in C.

Oh?  All the built-in trigger procedures are.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Question regarding triggers
@ 2003-10-20 13:56  achill@matrix.gatewaynet.com
  parent: A.Bhuvaneswaran <bhuvan@symonds.net>
  2 siblings, 0 replies; 6+ messages in thread

From: achill@matrix.gatewaynet.com @ 2003-10-20 13:56 UTC (permalink / raw)
  To: A.Bhuvaneswaran <bhuvan@symonds.net>; +Cc: Dmitri Fuerle <ffo2lp@yahoo.com>; pgsql-sql

On Mon, 20 Oct 2003, A.Bhuvaneswaran wrote:

> > Why dont you try to write your trigger in C?
> 
> Hi, one cannot write triggered procedures in C. Currently, it can only be
> written in plpsgql.

Where did you get that impression from?

Do an
SELECT tgrelid,tgfoid,proname from pg_trigger,pg_proc where 
tgfoid=pg_proc.oid and prolang=13;
in your system to check if you have any :)

> 
> > > CREATE FUNCTION "public"."check_shipment" () RETURNS trigger AS'
> > > begin
> > >     If new.shipment_type_id = 4 then
> > >         --do something
> > >     end if;
> > >     return new;
> > > end;
> > >  in the above example everything works if shipment_type_id is being
> > > updated.  If it is not I will receive a run-time error because
> > > shipment_type_id is not part of the record new.
> 
> All the fields of updated record must available in NEW variable.  Refer
> the manual for details. Forward your sql & run-time error for further 
> assistance.
> 
> regards,
> bhuvaneswaran
> 
> 

-- 
-Achilleus




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Question regarding triggers
@ 2003-10-20 15:07  Dmitri Fuerle <ffo2lp@yahoo.com>
  parent: A.Bhuvaneswaran <bhuvan@symonds.net>
  2 siblings, 0 replies; 6+ messages in thread

From: Dmitri Fuerle @ 2003-10-20 15:07 UTC (permalink / raw)
  To: pgsql-sql

  Thanks for the help.  I discovered my error while coming up with a better example.
 
 
Thanks,
  Dmitri


"A.Bhuvaneswaran" <bhuvan@symonds.net> wrote:
> Why dont you try to write your trigger in C?

Hi, one cannot write triggered procedures in C. Currently, it can only be
written in plpsgql.

> > CREATE FUNCTION "public"."check_shipment" () RETURNS trigger AS'
> > begin
> > If new.shipment_type_id = 4 then
> > --do something
> > end if;
> > return new;
> > end;
> > in the above example everything works if shipment_type_id is being
> > updated. If it is not I will receive a run-time error because
> > shipment_type_id is not part of the record new.

All the fields of updated record must available in NEW variable. Refer
the manual for details. Forward your sql & run-time error for further 
assistance.

regards,
bhuvaneswaran




---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2003-10-20 15:07 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-20 13:00 Question regarding triggers Dmitri Fuerle <ffo2lp@yahoo.com>
2003-10-20 13:22 ` achill@matrix.gatewaynet.com
2003-10-20 13:31   ` A.Bhuvaneswaran <bhuvan@symonds.net>
2003-10-20 13:48     ` Tom Lane <tgl@sss.pgh.pa.us>
2003-10-20 13:56     ` achill@matrix.gatewaynet.com
2003-10-20 15:07     ` Dmitri Fuerle <ffo2lp@yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox