trying to create db function which exclude non numeric values before insert&update
i have price field(data type = int) and i wanna create trigger (which i did) which will execute my function before insert&update .
main purpuse of my function is to run on every raw modification and exclude non numeric values from price field before store it .
my function looks like that :
BEGIN
NEW.price := REGEXP_REPLACE(NEW.price, '[^0-9]', '', 'g'); -- Remove non-numeric characters
NEW.price := NEW.price::int; -- Convert to integer
RETURN NEW;
END;
ps: whenever i try to insert something like 4,500 i get err,-"non intiger value"
main purpuse of my function is to run on every raw modification and exclude non numeric values from price field before store it .
my function looks like that :
BEGIN
NEW.price := REGEXP_REPLACE(NEW.price, '[^0-9]', '', 'g'); -- Remove non-numeric characters
NEW.price := NEW.price::int; -- Convert to integer
RETURN NEW;
END;
ps: whenever i try to insert something like 4,500 i get err,-"non intiger value"