Loop through table, look for word in text field, set boolean true if word exists

المشرف العام

Administrator
طاقم الإدارة
I want to create a function that loops through a table, and checks if a specific word exists in a text field. If it does, the function should set a Boolean field true. This is what ive come up with. I guess my execute command is wrong? Thank you very much and best regards.

CREATE OR REPLACE FUNCTION insertCarBooleans() Returns void AS $$ DECLARE location RECORD; BEGIN FOR location IN SELECT * FROM Ownlocations ORDER BY id LOOP EXECUTE 'UPDATE Ownlocations SET Ford = true WHERE cars LIKE 'Ford';
END LOOP; RETURN; END; $$ LANGUAGE plpgsql;

SELECT insertCarBooleans()


أكثر...
 
أعلى