pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Trigger
6+ messages / 5 participants
[nested] [flat]

* Trigger
@ 2005-02-16 13:43  Eugen Gass <gass@intend.de>
  0 siblings, 0 replies; 6+ messages in thread

From: Eugen Gass @ 2005-02-16 13:43 UTC (permalink / raw)
  To: pgsql-admin

Hi,

I'm trying to create a trigger on PostgreSQL

it should be like an oracle(sql) sample code:

create or replace trigger frei_polygon_sync
after INSERT on frei_polygon
Referencing NEW as newROW
for each row
Begin
 :newRow.objektid :=  :newRow.gid;
 :
end;

Can sombody help me to do the same on Postrgres

Best Regards

EG



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

* Re: [SQL] Trigger
@ 2005-02-17 09:29  Eugen Gass <gass@intend.de>
  0 siblings, 0 replies; 6+ messages in thread

From: Eugen Gass @ 2005-02-17 09:29 UTC (permalink / raw)
  To: pgsql-sql@postgresql.org; +Cc: pgsql-admin



Hi,
Thank you ALL for the fast help

it works fine with following code:

CREATE OR REPLACE FUNCTION synchronize () RETURNS trigger AS 'BEGIN
NEW.objectid := NEW.gid; RETURN NEW; END;' LANGUAGE plpgsql;

CREATE TRIGGER syncl_holz_lager AFTER INSERT ON holz_lagerplatz FOR EACH ROW
EXECUTE PROCEDURE synchronize();

Best Regards

Eugen




-----Ursprüngliche Nachricht-----
Von: Pavel Rabel [mailto:pavel@sajt.cz]
Gesendet: Mittwoch, 16. Februar 2005 21:43
An: Eugen Gass
Cc: pgsql-sql@postgresql.org
Betreff: Re: [SQL] Trigger


It requires a bit more work in PostgreSQL to create a trigger.

 From the documentation: "It is not currently possible to write a
SQL-language trigger function. Trigger functions can be written in C or
in some of the available procedural languages."

I guess you will prefer to write the trigger in PL/pgSQL, have a look at
http://www.postgresql.org/docs/8.0/interactive/plpgsql-trigger.html

Regards

Pavel

Eugen Gass wrote:

>Hi,
>
>I'm trying to create a trigger on PostgreSQL
>
>it should be like an oracle(sql) sample code:
>
>create or replace trigger frei_polygon_sync
>after INSERT on frei_polygon
>Referencing NEW as newROW
>for each row
>Begin
> :newRow.objektid :=  :newRow.gid;
> :
>end;
>
>Can sombody help me to do the same on Postrgres
>
>Thanks
>
>Best Regards
>
>EG
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
>
>
>




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

* trigger
@ 2005-11-18 11:16  Aftab Alam <aalam@tatashare.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Aftab Alam @ 2005-11-18 11:16 UTC (permalink / raw)
  To: pgsql-admin

Hello,

I want to create a trigger in PostgresSQL

In trigger, Before inserting the record, if data is already in the table,
the trigger fire the mesaage that data is already there, and after that
trigger ckeck for next insert statement.

Pleae help me in this regard , kindly  reply.

Regards,

_____

Aftab Alam

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

* Trigger
@ 2024-04-03 10:30  Rajesh Kumar <rajeshkumar.dba09@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Rajesh Kumar @ 2024-04-03 10:30 UTC (permalink / raw)
  To: Pgsql-admin <pgsql-admin@lists.postgresql.org>

I have one table with lot of columns (all vehicle details) and also have
updated_at column. Everytime there is a change in data, I want to backup
the original data into a new table?

What's the best option? A function and trigger before update?

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

* Re: Trigger
@ 2024-04-03 14:42  Thiemo Kellner <thiemo@gelassene-pferde.biz>
  parent: Rajesh Kumar <rajeshkumar.dba09@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Thiemo Kellner @ 2024-04-03 14:42 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org



Am 03.04.2024 um 12:30 schrieb Rajesh Kumar:
> I have one table with lot of columns (all vehicle details) and also have 
> updated_at column. Everytime there is a change in data, I want to backup 
> the original data into a new table?
> 
> What's the best option? A function and trigger before update?

I would say so.





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

* Re: Trigger
@ 2024-04-03 16:05  Erik Wienhold <ewie@ewie.name>
  parent: Thiemo Kellner <thiemo@gelassene-pferde.biz>
  0 siblings, 0 replies; 6+ messages in thread

From: Erik Wienhold @ 2024-04-03 16:05 UTC (permalink / raw)
  To: Thiemo Kellner <thiemo@gelassene-pferde.biz>; +Cc: pgsql-admin@lists.postgresql.org

On 2024-04-03 16:42 +0200, Thiemo Kellner wrote:
> Am 03.04.2024 um 12:30 schrieb Rajesh Kumar:
> > I have one table with lot of columns (all vehicle details) and also have
> > updated_at column. Everytime there is a change in data, I want to backup
> > the original data into a new table?
> > 
> > What's the best option? A function and trigger before update?
> 
> I would say so.

An AFTER trigger is better suited for that because it runs after
constraints are checked and the UPDATE has completed.  This avoids
unnecessary inserts into the audit table in case the UPDATE fails.

The docs have examples on table auditing[1].

[1] https://www.postgresql.org/docs/current/plpgsql-trigger.html#PLPGSQL-TRIGGER-AUDIT-EXAMPLE

-- 
Erik





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


end of thread, other threads:[~2024-04-03 16:05 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-16 13:43 Trigger Eugen Gass <gass@intend.de>
2005-02-17 09:29 Re: [SQL] Trigger Eugen Gass <gass@intend.de>
2005-11-18 11:16 trigger Aftab Alam <aalam@tatashare.com>
2024-04-03 10:30 Trigger Rajesh Kumar <rajeshkumar.dba09@gmail.com>
2024-04-03 14:42 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
2024-04-03 16:05   ` Erik Wienhold <ewie@ewie.name>

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