473,586 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

plpgsql trigger function with arguments

I'm sure I saw something like this on the postgresql web
site but the the search function is down in the documentation
area.

I'm unable to pass a function arguments in a CREATE
TRIGGER statement.

What am I doing wrong here?

CREATE FUNCTION pregs_func (VARCHAR(15))
RETURNS trigger
LANGUAGE plpgsql
AS '
DECLARE
trigger_type ALIAS FOR $1;

BEGIN
IF trigger_type = ''insert'' THEN
...
END IF;
END;
';

CREATE TRIGGER pregs_insert_tr igger
AFTER INSERT
ON pregs FOR EACH ROW
EXECUTE PROCEDURE pregs_func('ins ert');

CREATE TRIGGER pregs_update_tr igger
AFTER UPDATE
ON pregs FOR EACH ROW
EXECUTE PROCEDURE pregs_func('upd ate');

The CREATE TRIGGER statements return:
ERROR: CreateTrigger: function pregs_func() does not exist
I tried doing variations on:
create trigger pregs_insert_tr igger after insert on pregs
for each row execute procedure
pregs_func (cast('insert' as varchar(15)));

thinking that I don't have the right function because the
datatypes don't match, but I get:
ERROR: parser: parse error at or near "cast" at character 106

PostgreSQL 7.3.

Thanks,

Karl <ko*@meme.com >
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
2 5513
hello

You have to write functions without params. Params for triggers are
accessed not via function params, but via special variable TG_ARGV[]

http://archives.postgresql.org/pgsql...3/msg01021.php

regards
Pavel Stehule

On Tue, 2 Mar 2004, Karl O. Pinc wrote:
I'm sure I saw something like this on the postgresql web
site but the the search function is down in the documentation
area.

I'm unable to pass a function arguments in a CREATE
TRIGGER statement.

What am I doing wrong here?

CREATE FUNCTION pregs_func (VARCHAR(15))
RETURNS trigger
LANGUAGE plpgsql
AS '
DECLARE
trigger_type ALIAS FOR $1;

BEGIN
IF trigger_type = ''insert'' THEN
...
END IF;
END;
';

CREATE TRIGGER pregs_insert_tr igger
AFTER INSERT
ON pregs FOR EACH ROW
EXECUTE PROCEDURE pregs_func('ins ert');

CREATE TRIGGER pregs_update_tr igger
AFTER UPDATE
ON pregs FOR EACH ROW
EXECUTE PROCEDURE pregs_func('upd ate');

The CREATE TRIGGER statements return:
ERROR: CreateTrigger: function pregs_func() does not exist
I tried doing variations on:
create trigger pregs_insert_tr igger after insert on pregs
for each row execute procedure
pregs_func (cast('insert' as varchar(15)));

thinking that I don't have the right function because the
datatypes don't match, but I get:
ERROR: parser: parse error at or near "cast" at character 106

PostgreSQL 7.3.

Thanks,

Karl <ko*@meme.com >
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #2
On Tue, 02 Mar 2004 21:35:27 -0600, Karl O. Pinc wrote:

<..>>
CREATE TRIGGER pregs_insert_tr igger
AFTER INSERT
ON pregs FOR EACH ROW
EXECUTE PROCEDURE pregs_func('ins ert');

CREATE TRIGGER pregs_update_tr igger
AFTER UPDATE
ON pregs FOR EACH ROW
EXECUTE PROCEDURE pregs_func('upd ate');


According to the docs, this is unnecessary. A trigger function
automatically has a number of variables instantiated for it:

http://www.postgresql.org/docs/7.3/s...plpgsqltrigger

The TG_OP variable contains 'INSERT','UPDAT E' or 'DELETE'.

--
Colin Fox
President
CF Consulting Inc.

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1980
by: Josué Maldonado | last post by:
Hi list, That's the question, anyone knows a way to do that? Thanks in advance, Josue Maldonado.
6
3962
by: Martin Marques | last post by:
We are trying to make some things work with plpgsql. The problem is that I built several functions that call one another, and I thought that the way of calling it was just making the assign: var:=func1(arg1,arg2); which gave me an error near ")". Now if I did the same, but like this:
3
5053
by: Philippe Lang | last post by:
Hello, How can open a unix shell from a PLPGSQL function / trigger? I would like to send an email from a postgres database, and also send some unix commands to the server, through the database... Thanks ------------------------- Philippe Lang
10
2926
by: lnd | last post by:
After copied pg database from one PC to another -I could not find plpgsql function(s) in the copied database. -had to instal plpgsql language handler again -whilst tables and data moved fine The copy included all under /cygwin/usr/local/pgsql/data and database was down while making a copy.
2
7180
by: Karl O. Pinc | last post by:
I'd like to write: SELECT larger(colA, colB) FROM foo and am wondering the best way to go about it. (Really, I'd like the larger() function to take an arbitrary number of arguments but I don't see how to do that.) Are there significant performance penalities if I were to use a
14
5781
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where the problem is. I keep getting errors like (the first is my debug output): NOTICE: last cycle is: 11 WARNING: Error occurred while executing...
2
3808
by: Mark Cave-Ayland | last post by:
Hi everyone, I'm trying to write a recursive plpgsql function in PostgreSQL 7.4.2 that given a tree node id (ictid) will return all the nodes below it in the tree, one row per node. When I try and execute the function I get the following error message: CONTEXT: PL/pgSQL function "findsubcategories" line 15 at for over select rows...
1
2191
by: Karl O. Pinc | last post by:
FYI, mostly. But I do have questions as to how to write code that will continue to work in subsequent postgresql versions. See code below. begintest() uses EXIT to exit a BEGIN block from within nested loops. No problem. begintest2() simplifies this, omitting the nested loops. Still no problem.
1
1240
by: Stefano Bonnin | last post by:
CORRECTION, even if I define a stupid "hello world" trigger function the problem is present: for example CREATE FUNCTION sns_action () RETURNS TRIGGER AS ' BEGIN RAISE NOTICE ''hello world!''; RETURN NEW;
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.