pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedError in trigger
2+ messages / 2 participants
[nested] [flat]
* Error in trigger
@ 2007-01-19 01:18 Negandhi, Nishith <Nishith.Negandhi@infoUSA.com>
0 siblings, 1 reply; 2+ messages in thread
From: Negandhi, Nishith @ 2007-01-19 01:18 UTC (permalink / raw)
To: pgsql-admin
Hi,
All my tables in the database have "CreateDate" and "LastUpdateDate"
columns. I need to create a trigger wherein on insert the "CreateDate"
column is inserted with the current date. On Update the "LastUpdateDate"
is inserted with the current date.
I tried the insert trigger as mentioned below:
CREATE FUNCTION "CreateDate_F"() RETURNS TRIGGER AS $CreateDate_T$
BEGIN
insert into "CreateDate" values (CURRENT_TIMESTAMP);
END;
$CreateDate_T$ LANGUAGE plpgsql;
CREATE TRIGGER "Create_Date_T" AFTER INSERT ON "CreateDate"
FOR EACH STATEMENT EXECUTE PROCEDURE "CreateDate_F"();
However, when I run the insert on the said table, I get the following
error:
ERROR: stack depth limit exceeded
HINT: Increase the configuration parameter "max_stack_depth".
CONTEXT: SQL statement "insert into "CreateDate" values
(CURRENT_TIMESTAMP)"
PL/pgSQL function "CreateDate_F" line 2 at SQL statement
Other than the above, is there any other way of doing this.???
Any suggestions please .???
Regards
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Error in trigger
@ 2007-01-19 03:16 Stephan Szabo <sszabo@megazone.bigpanda.com>
parent: Negandhi, Nishith <Nishith.Negandhi@infoUSA.com>
0 siblings, 0 replies; 2+ messages in thread
From: Stephan Szabo @ 2007-01-19 03:16 UTC (permalink / raw)
To: Negandhi, Nishith <Nishith.Negandhi@infoUSA.com>; +Cc: pgsql-admin
On Thu, 18 Jan 2007, Negandhi, Nishith wrote:
> Hi,
> All my tables in the database have "CreateDate" and "LastUpdateDate"
> columns. I need to create a trigger wherein on insert the "CreateDate"
> column is inserted with the current date. On Update the "LastUpdateDate"
> is inserted with the current date.
>
> I tried the insert trigger as mentioned below:
>
> CREATE FUNCTION "CreateDate_F"() RETURNS TRIGGER AS $CreateDate_T$
> BEGIN
> insert into "CreateDate" values (CURRENT_TIMESTAMP);
> END;
> $CreateDate_T$ LANGUAGE plpgsql;
>
> CREATE TRIGGER "Create_Date_T" AFTER INSERT ON "CreateDate"
> FOR EACH STATEMENT EXECUTE PROCEDURE "CreateDate_F"();
I think you really want to be using a before row trigger and setting
NEW."CreateDate" in it if you want each row to have the appropriate
creation date (and a similar thing for the update date).
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2007-01-19 03:16 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-01-19 01:18 Error in trigger Negandhi, Nishith <Nishith.Negandhi@infoUSA.com>
2007-01-19 03:16 ` Stephan Szabo <sszabo@megazone.bigpanda.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