Advertisement
Pandaaaa906

normalize_package

Jul 22nd, 2022
1,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 1mL*7之类的,类似计算的无解
  2. CREATE OR REPLACE FUNCTION normalize_package(text) returns double precision as $BODY$
  3. select CASE lower(COALESCE(substring($1, '([muμMKk]?[GLgl])$'::text), 'mg'::text))
  4.     WHEN 'g'::text THEN (1000)::numeric
  5.     WHEN 'mg'::text THEN (1)::numeric
  6.     WHEN 'ml'::text THEN (1000)::numeric
  7.     WHEN 'l'::text THEN (1000000)::numeric
  8.     WHEN 'kg'::text THEN (1000000)::numeric
  9.     WHEN 'ug'::text THEN 0.001
  10.     WHEN 'μg'::text THEN 0.001
  11.     WHEN 'μl'::text THEN (1)::numeric
  12.     WHEN 'ul'::text THEN (1)::numeric
  13.     ELSE NULL::numeric
  14.     END * COALESCE((substring($1, '(\d+(\.\d+)?)\s?[muμMKk]?[GLgl]'::text))::double precision, NULL::double precision);
  15.        
  16.         $BODY$
  17.   LANGUAGE sql IMMUTABLE STRICT
  18.   COST 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement