By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,809 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,809 IT Pros & Developers. It's quick & easy.

Access to an element of array NEW in TCL

P: n/a
Hi list,

Is there a way to access an especific element of the array NEW in an TCL
trigger, I have a loop that goes for each field (thanks Ian & Darren)
like this:

foreach id [array names NEW] {

then I can refer to an element with this (inside the loop):
$NEW($id)

I do need to make a reference to an especific column name (duser) in
that array to get its value, I already tried $NEW(duser),
$NEW(\'duser\') but didn't work. I'll appreciate any help from you

Thanks
Josue Maldonado

Nov 11 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The way you have it should work i.e. if the NEW array has a field called
duser in it you will be able to access it using $NEW(duser)

Put in an elog notice and do [array names NEW] in it.
Run the function and see what variables are available to you then you
should be able to call them just like shown below

-bash-2.05b$ tclsh
% set NEW(duser) darren
darren
% set NEW(cuser) carl
carl
% foreach id [array names NEW] { puts $NEW($id) }
carl
darren
% puts $NEW(duser)
darren
% puts $NEW(cuser)
carl

HTH
Darren

On Wed, 3 Sep 2003, Josué Maldonado wrote:
Hi list,

Is there a way to access an especific element of the array NEW in an TCL
trigger, I have a loop that goes for each field (thanks Ian & Darren)
like this:

foreach id [array names NEW] {

then I can refer to an element with this (inside the loop):
$NEW($id)

I do need to make a reference to an especific column name (duser) in
that array to get its value, I already tried $NEW(duser),
$NEW(\'duser\') but didn't work. I'll appreciate any help from you

Thanks
Josue Maldonado
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)


--
Darren Ferguson
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #2

P: n/a
As long as it is an insert or update trigger that fires your tcl
function, you have access to the NEW array. The foreach loop uses the
tcl command [array names NEW] to suck out the names of the existing
members of the array. If a column called duser exists in the NEW array
(it is part of the inserted tuple, or not updated to null) you should be
able to access it as

$NEW(duser)

What error are you getting? If the duser column is null, there is no
array member called NEW(duser) and you will get an error to that effect.

Josué Maldonado wrote:
Hi list,

Is there a way to access an especific element of the array NEW in an
TCL trigger, I have a loop that goes for each field (thanks Ian &
Darren) like this:

foreach id [array names NEW] {

then I can refer to an element with this (inside the loop):
$NEW($id)

I do need to make a reference to an especific column name (duser) in
that array to get its value, I already tried $NEW(duser),
$NEW(\'duser\') but didn't work. I'll appreciate any help from you

Thanks
Josue Maldonado
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)



---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.