Question

got strange error "Correlation name 'Club' not found" but the table Club is in the DB. I think the problem is after inserting the values:

ALTER TRIGGER "tg_add_club" AFTER INSERT,
UPDATE ON Club
REFERENCING NEW AS item
FOR EACH ROW
WHEN (item.address NOT IN (SELECT name FROM Place))
BEGIN 
 //DECLARE i_id INTEGER;
 INSERT INTO Place(name)
 VALUES (item.address);
 //SELECT @@identity INTO i_id;
 UPDATE Club SET place = (SELECT id FROM Place WHERE name=item.address)
 WHERE Name = item.name; //AND Place.name = item.address;
END

I think the problem is somewhere after VALUES (item.address), but I'm not sure.

Have tried different things with it, but still nothing works. Thanks for reading!

Was it helpful?

Solution

The problem was, that the SET place and WHERE Name should be the same, or it would give me the error. Should work now:

UPDATE Club SET Name = (SELECT id FROM Place WHERE name=item.address) WHERE Name = item.name;

If it's new address, then the random id is made and Club gets the id from the table, where all the addresses are stored.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top