Domanda

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!

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top