how to output the string which include %
Postgres complain synax error when error string include %
IF ((NEW.percentage/power(10, NEW.decimals)) > 100) THEN
RAISE EXCEPTION '100001, TRIG: INSERT/UPDATE Failed: percentage must <= 100%.' USING ERRCODE='ZZ001';
END IF;
when you execute the trigger it report syntax error
psql -h 10.20.7.4 -d ct1 -U abc -f abc.trig
psql:abc.trig.pg:340: ERROR: too few parameters specified for RAISE
CONTEXT: compilation of PL/pgSQL function "abc_aiufer" near line 284
Postgres official documents states that If you want to include % in the result string, use double percentages %% .
therfore correct the trigger as below, the trigger compile successfully.
IF ((NEW.percentage/power(10, NEW.decimals)) > 100) THEN
RAISE EXCEPTION '100001, TRIG: INSERT/UPDATE Failed: percentage must <= 100%%.' USING ERRCODE='ZZ001';
END IF;