Advertisement
clovek

Untitled

Jan 23rd, 2025
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION public.uprav_tgr2()
  2.  RETURNS integer
  3.  LANGUAGE plpgsql
  4. AS $function$
  5.   begin  
  6.     update tgr2 set namefrom_kratky=(select case when cm_skr<>'' then cm_skr else cm_nao end  from ( select a,  trim(split_part(namefrom,', ',a)) as _1 from generate_series(1,10) s(a)) t1,(select cm_nao,cm_skr from acm where acm._podnik=1 and cm_nao<>'' ) t2 where trim(cm_nao)=_1 order by a,case when cm_skr='' then 1 else 0 end  limit 1),nameto_kratky=(select case when cm_skr<>'' then cm_skr else cm_nao end  from ( select a,  trim(split_part(nameto,',',a)) as _1 from generate_series(1,10) s(a)) t1,(select cm_nao,cm_skr from acm where acm._podnik=1  and cm_nao<>'') t2 where cm_nao=trim(_1) order by a,case when cm_skr='' then 1 else 0 end  limit 1)    where (_deleted='f' or _deleted is null ) and latfrom<>0 and timefrom>'2024-01-01' and (trim(namefrom_kratky)='' or trim(nameto_kratky)='' or namefrom_kratky is null or nameto_kratky is null   ) and carname in (select gh_ozn from tgh where _podnik=1 and _deleted='f' and _rok=2024) ;
  7.     update tgr2 set namefrom_kratky=(select case when cm_skr<>'' then cm_skr else cm_nao end  from ( select a,  trim(split_part(namefrom,', ',a)) as _1 from generate_series(1,10) s(a)) t1,(select cm_nao,cm_skr from acm where acm._podnik=3 and cm_nao<>'' ) t2 where trim(cm_nao)=_1 order by a,case when cm_skr='' then 1 else 0 end  limit 1),nameto_kratky=(select case when cm_skr<>'' then cm_skr else cm_nao end  from ( select a,  trim(split_part(nameto,',',a)) as _1 from generate_series(1,10) s(a)) t1,(select cm_nao,cm_skr from acm where acm._podnik=3  and cm_nao<>'') t2 where cm_nao=trim(_1) order by a,case when cm_skr='' then 1 else 0 end  limit 1)    where (_deleted='f' or _deleted is null ) and latfrom<>0 and timefrom>'2024-01-01' and (trim(namefrom_kratky)='' or trim(nameto_kratky)='' or namefrom_kratky is null or nameto_kratky is null   ) and carname in (select gh_ozn from tgh where _podnik=3 and _deleted='f' and _rok=2024) ;
  8.     update tgr2 set namefrom_kratky=case when namefrom_kratky='' or namefrom_kratky is null then 'XXX' else namefrom_kratky end,
  9.       nameto_kratky=case when nameto_kratky='' or nameto_kratky is null then 'XXX' else nameto_kratky end
  10.       where (_deleted='f' or _deleted is null ) and latfrom<>0 and timefrom>'2024-01-01' and (trim(namefrom_kratky)='' or trim(nameto_kratky)='' or namefrom_kratky is null or nameto_kratky is null   );
  11.     return 1;
  12.   end
  13. $function$
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement