Postgresql function doesn't work properly -
why function returning half zip codes?
i mean if
insert address(zip_code) values(99-100)
it's doesn't work properly, because it's adding "99-".
create function normalize_zip_code() returns trigger $$ begin if length(new.zip_code)<=4 , length(new.zip_code)>=6 raise exception 'wrong zip code!'; elsif length(new.zip_code)=6 , (substring(new.zip_code, 3, 1)='-') new.zip_code:= concat((substring(new.zip_code, 1, 2))::varchar(2),(substring(new.zip_code, 3, 1))::varchar(1), (substring(new.zip_code, 3, 5))::varchar(3)); return new; else new.zip_code := concat((substring(new.zip_code, 1, 2))::varchar(2),'-' (substring(new.zip_code, 3, 5))::varchar(3)); return new; end if; end; $$ language plpgsql;
Comments
Post a Comment