Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

If a listener nods his head when you're explaining your program, wake him up.


programming / comp.lang.tcl / Re: really stuck on this pl/tcl

SubjectAuthor
* really stuck on this pl/tclJim McNamara
`* Re: really stuck on this pl/tclJim McNamara
 `* Re: really stuck on this pl/tclProfessor Zarkov
  `- Re: really stuck on this pl/tclJim McNamara

1
Subject: really stuck on this pl/tcl
From: Jim McNamara
Newsgroups: comp.lang.tcl
Date: Tue, 17 May 2022 02:46 UTC
X-Received: by 2002:a05:6214:528e:b0:45a:95ff:337f with SMTP id kj14-20020a056214528e00b0045a95ff337fmr18305792qvb.78.1652755607607;
Mon, 16 May 2022 19:46:47 -0700 (PDT)
X-Received: by 2002:a05:6870:51cb:b0:e2:aafb:cbb9 with SMTP id
b11-20020a05687051cb00b000e2aafbcbb9mr16775511oaj.39.1652755607327; Mon, 16
May 2022 19:46:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 16 May 2022 19:46:47 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=209.58.130.53; posting-account=uhkbQAoAAAD0g7P5rsSUhpzoEB9iE0Iz
NNTP-Posting-Host: 209.58.130.53
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <52860bbc-b301-458a-939c-2f2eda2a8db1n@googlegroups.com>
Subject: really stuck on this pl/tcl
From: nefariou...@gmail.com (Jim McNamara)
Injection-Date: Tue, 17 May 2022 02:46:47 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
Hi guys-

I'm trying to get a function to return nothing, so that it won't insert a new
record in the table if the fk_emp_id = 1. In regular triggers for postgres,
I used something like return NULL. I tried that and this will execute no matter
what. I'm interested in blocking an insert from happening! TIA. roboloki

CREATE OR REPLACE FUNCTION trigfunc_insert2() RETURNS trigger AS $$
    switch $TG_op {
        INSERT {
    set param $NEW($1)
            spi_exec "select count(fk_emp_id) as foo from pos where fk_emp_id = $param";
if {$foo == 1 } { # what goes here to stop the insert}
        }   
        default {
            return OK
        }
    }
    return OK
$$ LANGUAGE pltcl;

CREATE TRIGGER trig_mytab_foo BEFORE INSERT on pos
    FOR EACH ROW EXECUTE FUNCTIONtrigfunc_insert2('fk_emp_id');


Subject: Re: really stuck on this pl/tcl
From: Jim McNamara
Newsgroups: comp.lang.tcl
Date: Tue, 17 May 2022 04:03 UTC
References: 1
X-Received: by 2002:a05:6214:518d:b0:45a:933f:965d with SMTP id kl13-20020a056214518d00b0045a933f965dmr18814926qvb.94.1652760203192;
Mon, 16 May 2022 21:03:23 -0700 (PDT)
X-Received: by 2002:a05:6808:14cc:b0:328:b183:c2cc with SMTP id
f12-20020a05680814cc00b00328b183c2ccmr9530093oiw.150.1652760202883; Mon, 16
May 2022 21:03:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 16 May 2022 21:03:22 -0700 (PDT)
In-Reply-To: <52860bbc-b301-458a-939c-2f2eda2a8db1n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=209.58.130.53; posting-account=uhkbQAoAAAD0g7P5rsSUhpzoEB9iE0Iz
NNTP-Posting-Host: 209.58.130.53
References: <52860bbc-b301-458a-939c-2f2eda2a8db1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4a98f5fd-1702-4bd7-885e-855c803a1ff7n@googlegroups.com>
Subject: Re: really stuck on this pl/tcl
From: nefariou...@gmail.com (Jim McNamara)
Injection-Date: Tue, 17 May 2022 04:03:23 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2464
View all headers
On Monday, May 16, 2022 at 10:46:49 PM UTC-4, Jim McNamara wrote:
Hi guys-

I'm trying to get a function to return nothing, so that it won't insert a new
record in the table if the fk_emp_id = 1. In regular triggers for postgres,
I used something like return NULL. I tried that and this will execute no matter
what. I'm interested in blocking an insert from happening! TIA. roboloki

CREATE OR REPLACE FUNCTION trigfunc_insert2() RETURNS trigger AS $$
switch $TG_op {
INSERT {
set param $NEW($1)
spi_exec "select count(fk_emp_id) as foo from pos where fk_emp_id = $param";
if {$foo == 1 } { # what goes here to stop the insert}
}
default {
return OK
}
}
return OK
$$ LANGUAGE pltcl;

CREATE TRIGGER trig_mytab_foo BEFORE INSERT on pos
FOR EACH ROW EXECUTE FUNCTIONtrigfunc_insert2('fk_emp_id');

Hi guys-

This is an example of doing it in regular postgresql trigger language.

CREATE OR REPLACE FUNCTION test() RETURNS TRIGGER AS $$
   BEGIN
   if EXISTS (select fk_emp_id from pos where fk_emp_id = new.fk_emp_id ) then
   RETURN NULL;
else
   RETURN NEW;
   end if;
end;
$$ LANGUAGE plpgsql;

CREATE TRIGGER example_trigger BEFORE INSERT ON pos
FOR EACH ROW EXECUTE PROCEDURE test();

THANKS FOR ANY INPUT!
roboloki




Subject: Re: really stuck on this pl/tcl
From: Professor Zarkov
Newsgroups: comp.lang.tcl
Date: Tue, 17 May 2022 07:38 UTC
References: 1 2
X-Received: by 2002:a05:620a:4488:b0:6a0:2aab:a736 with SMTP id x8-20020a05620a448800b006a02aaba736mr15689197qkp.717.1652773139346;
Tue, 17 May 2022 00:38:59 -0700 (PDT)
X-Received: by 2002:aca:1a09:0:b0:325:90ab:a812 with SMTP id
a9-20020aca1a09000000b0032590aba812mr15255439oia.131.1652773139099; Tue, 17
May 2022 00:38:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 17 May 2022 00:38:58 -0700 (PDT)
In-Reply-To: <4a98f5fd-1702-4bd7-885e-855c803a1ff7n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=193.240.59.18; posting-account=Pd33KQoAAADkV1lvxFFfDnZl1Rk1Rh28
NNTP-Posting-Host: 193.240.59.18
References: <52860bbc-b301-458a-939c-2f2eda2a8db1n@googlegroups.com> <4a98f5fd-1702-4bd7-885e-855c803a1ff7n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <07aa0034-4930-4ae9-964a-e30f6580fe73n@googlegroups.com>
Subject: Re: really stuck on this pl/tcl
From: zarko...@googlemail.com (Professor Zarkov)
Injection-Date: Tue, 17 May 2022 07:38:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3272
View all headers
On Tuesday, May 17, 2022 at 5:03:25 AM UTC+1, nefario...@gmail.com wrote:
On Monday, May 16, 2022 at 10:46:49 PM UTC-4, Jim McNamara wrote:
Hi guys-

I'm trying to get a function to return nothing, so that it won't insert a new
record in the table if the fk_emp_id = 1. In regular triggers for postgres,
I used something like return NULL. I tried that and this will execute no matter
what. I'm interested in blocking an insert from happening! TIA. roboloki

CREATE OR REPLACE FUNCTION trigfunc_insert2() RETURNS trigger AS $$
switch $TG_op {
INSERT {
set param $NEW($1)
spi_exec "select count(fk_emp_id) as foo from pos where fk_emp_id = $param";
if {$foo == 1 } { # what goes here to stop the insert}
}
default {
return OK
}
}
return OK
$$ LANGUAGE pltcl;

CREATE TRIGGER trig_mytab_foo BEFORE INSERT on pos
FOR EACH ROW EXECUTE FUNCTIONtrigfunc_insert2('fk_emp_id');
Hi guys-

This is an example of doing it in regular postgresql trigger language.

CREATE OR REPLACE FUNCTION test() RETURNS TRIGGER AS $$
BEGIN
if EXISTS (select fk_emp_id from pos where fk_emp_id = new.fk_emp_id ) then
RETURN NULL;
else
RETURN NEW;
end if;
end;
$$ LANGUAGE plpgsql;

CREATE TRIGGER example_trigger BEFORE INSERT ON pos
FOR EACH ROW EXECUTE PROCEDURE test();

THANKS FOR ANY INPUT!
roboloki

The pltcl manual page suggests that returning SKIP should be the equivalent to a NULL in plpgsql.

The return value from a trigger function can be one of the strings OK or SKIP, or a list of column name/value pairs. If the return value is OK, the operation (INSERT/UPDATE/DELETE) that fired the trigger will proceed normally.. SKIP tells the trigger manager to silently suppress the operation for this row

Regards,
Bob


Subject: Re: really stuck on this pl/tcl
From: Jim McNamara
Newsgroups: comp.lang.tcl
Date: Tue, 17 May 2022 16:47 UTC
References: 1 2 3
X-Received: by 2002:a05:620a:24cd:b0:6a0:414c:a648 with SMTP id m13-20020a05620a24cd00b006a0414ca648mr16965120qkn.465.1652806047125;
Tue, 17 May 2022 09:47:27 -0700 (PDT)
X-Received: by 2002:aca:1a09:0:b0:325:90ab:a812 with SMTP id
a9-20020aca1a09000000b0032590aba812mr16412367oia.131.1652806046782; Tue, 17
May 2022 09:47:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 17 May 2022 09:47:26 -0700 (PDT)
In-Reply-To: <07aa0034-4930-4ae9-964a-e30f6580fe73n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=209.58.130.42; posting-account=uhkbQAoAAAD0g7P5rsSUhpzoEB9iE0Iz
NNTP-Posting-Host: 209.58.130.42
References: <52860bbc-b301-458a-939c-2f2eda2a8db1n@googlegroups.com>
<4a98f5fd-1702-4bd7-885e-855c803a1ff7n@googlegroups.com> <07aa0034-4930-4ae9-964a-e30f6580fe73n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <22392ec4-467d-407a-bf2a-2d1c5f2b8023n@googlegroups.com>
Subject: Re: really stuck on this pl/tcl
From: nefariou...@gmail.com (Jim McNamara)
Injection-Date: Tue, 17 May 2022 16:47:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3750
View all headers
On Tuesday, May 17, 2022 at 3:39:01 AM UTC-4, Professor Zarkov wrote:
On Tuesday, May 17, 2022 at 5:03:25 AM UTC+1, nefario...@gmail.com wrote:
On Monday, May 16, 2022 at 10:46:49 PM UTC-4, Jim McNamara wrote:
Hi guys-

I'm trying to get a function to return nothing, so that it won't insert a new
record in the table if the fk_emp_id = 1. In regular triggers for postgres,
I used something like return NULL. I tried that and this will execute no matter
what. I'm interested in blocking an insert from happening! TIA. roboloki

CREATE OR REPLACE FUNCTION trigfunc_insert2() RETURNS trigger AS $$
switch $TG_op {
INSERT {
set param $NEW($1)
spi_exec "select count(fk_emp_id) as foo from pos where fk_emp_id = $param";
if {$foo == 1 } { # what goes here to stop the insert}
}
default {
return OK
}
}
return OK
$$ LANGUAGE pltcl;

CREATE TRIGGER trig_mytab_foo BEFORE INSERT on pos
FOR EACH ROW EXECUTE FUNCTIONtrigfunc_insert2('fk_emp_id');
Hi guys-

This is an example of doing it in regular postgresql trigger language.

CREATE OR REPLACE FUNCTION test() RETURNS TRIGGER AS $$
BEGIN
if EXISTS (select fk_emp_id from pos where fk_emp_id = new.fk_emp_id ) then
RETURN NULL;
else
RETURN NEW;
end if;
end;
$$ LANGUAGE plpgsql;

CREATE TRIGGER example_trigger BEFORE INSERT ON pos
FOR EACH ROW EXECUTE PROCEDURE test();

THANKS FOR ANY INPUT!
roboloki
The pltcl manual page suggests that returning SKIP should be the equivalent to a NULL in plpgsql.

The return value from a trigger function can be one of the strings OK or SKIP, or a list of column name/value pairs. If the return value is OK, the operation (INSERT/UPDATE/DELETE) that fired the trigger will proceed normally. SKIP tells the trigger manager to silently suppress the operation for this row

Regards,
Bob
I figured it out instantly when I woke up. I read your response and realize I put:
SKIP instead of return SKIP.
As my co-worker used to say, it was my houdini door.
thanks so much for getting back to me.
jim






1
rocksolid light 0.7.2
clearneti2ptor