Обсуждение: trigger parameters, what am I doing wrong ??
Hi guys. I'm trying to pass a parameter to trigger procedure but it's not working and I have no idea why since it looks pretty ok. Here's what I do :
CREATE OR REPLACE FUNCTION test_proc()
RETURNS "trigger" AS
$BODY$
DECLARE
chk boolean;
par integer := TG_ARGV[0];
BEGIN
RAISE NOTICE 'TG_ARGV = %, TG_NARGS = %, par = %', TG_ARGV[0], TG_NARGS, par;
-- [...] some computations
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER jks_test_proc_tg
AFTER UPDATE
ON test_table
FOR EACH ROW
EXECUTE PROCEDURE test_proc(42);
And here's what RAISE NOTICE looks like : NOTICE: TG_ARGV = <NULL>, TG_NARGS = 0, par = <NULL>
What's wrong with it ?? I'm running 8.1.4
regards
mk
CREATE OR REPLACE FUNCTION test_proc()
RETURNS "trigger" AS
$BODY$
DECLARE
chk boolean;
par integer := TG_ARGV[0];
BEGIN
RAISE NOTICE 'TG_ARGV = %, TG_NARGS = %, par = %', TG_ARGV[0], TG_NARGS, par;
-- [...] some computations
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER jks_test_proc_tg
AFTER UPDATE
ON test_table
FOR EACH ROW
EXECUTE PROCEDURE test_proc(42);
And here's what RAISE NOTICE looks like : NOTICE: TG_ARGV = <NULL>, TG_NARGS = 0, par = <NULL>
What's wrong with it ?? I'm running 8.1.4
regards
mk
"Marcin Krawczyk" <jankes.mk@gmail.com> writes:
> And here's what RAISE NOTICE looks like : NOTICE: TG_ARGV = <NULL>,
> TG_NARGS = 0, par = <NULL>
> What's wrong with it ?? I'm running 8.1.4
Works for me:
regression=# insert into test_table values(1);
INSERT 0 1
regression=# update test_table set f1 = 2;
NOTICE: TG_ARGV = 42, TG_NARGS = 1, par = 42
UPDATE 1
You need to show a more complete example of what you're doing.
regards, tom lane
With some version (but I don't remember which) I had the same problem.
I solved it by assigning TG_ARGV[0] to a variable and use the variable in the RAISE NOTICE.
>>> Tom Lane <tgl@sss.pgh.pa.us> 2008-10-09 19:22 >>>
"Marcin Krawczyk" <jankes.mk@gmail.com> writes:
> And here's what RAISE NOTICE looks like : NOTICE: TG_ARGV = <NULL>,
> TG_NARGS = 0, par = <NULL>
> What's wrong with it ?? I'm running 8.1.4
Works for me:
regression=# insert into test_table values(1);
INSERT 0 1
regression=# update test_table set f1 = 2;
NOTICE: TG_ARGV = 42, TG_NARGS = 1, par = 42
UPDATE 1
You need to show a more complete example of what you're doing.
regards, tom lane
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
>>> Tom Lane <tgl@sss.pgh.pa.us> 2008-10-09 19:22 >>>
"Marcin Krawczyk" <jankes.mk@gmail.com> writes:
> And here's what RAISE NOTICE looks like : NOTICE: TG_ARGV = <NULL>,
> TG_NARGS = 0, par = <NULL>
> What's wrong with it ?? I'm running 8.1.4
Works for me:
regression=# insert into test_table values(1);
INSERT 0 1
regression=# update test_table set f1 = 2;
NOTICE: TG_ARGV = 42, TG_NARGS = 1, par = 42
UPDATE 1
You need to show a more complete example of what you're doing.
regards, tom lane
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql