Well, TG_ARGV is not a column in your "cmd" table, so it is surely no surprise that "old.tg_argv" returns an error. What you want is "old.cmd_id" and to do this you need to build the delete query dynamically using string concatentation and then execute it ...