使用postgresql时出现的问题
创建表时出现的问题
create table enterprise_wide_table as
select
a.entname,b.code_name as area,a.dom
,c.nic_id
,d.fulltitle
,a.opscope,a.entstatus
,a.regcap ,a.esdate
,date_part('year',now()) - to_char(a.esdate,'yyyy') as year
,e.ancheyear ,e.netinc ,e.liagro ,e.maibusinc ,e.vendinc
,a.empnum ,a.enttype_name
,case
when a.empnum >= '1000' and replace(e.maibusinc,'万','')>='40000' then '大'
when '1000'>a.empnum and replace(e.maibusinc,'万','')>='300' and '40000'>e.maibusinc and e.maibusinc>='2000' then '中'
when '300'>a.empnum and replace(e.maibusinc,'万','')>='20' and '2000'>e.maibusinc and e.maibusinc>='300' then '小'
when a.empnum< '20' and replace(e.maibusinc,'万','')<'300' then '微'
else 'NULL'
end as enterprise_scale
,f.pl_nums ,f.pr_nums
from
public.chongqign_area_code_temporary a
inner join public.chongqign_area_code_csv b on a.domdistrict = b.code::varchar
left join public.company_class c on a.entid = c.entid and (substr(c.nic_id ,1,1)='B' or substr(c.nic_id ,1,1)='C' or substr(c.nic_id ,1,1)='D')
left join public.code_nic d on substr(c.nic_id ,1,1) = d.code
left join public.company_ar_assetsinfo e on e.entid = a.entid
left join public.nacao_techindex f on f.entid = a.entid
SQL 错误 [XXUUU]: ERROR: command is too large: 853488551 bytes (max: 256000000)
出现问题原因
创建表太大了,内存不够用了
解决方案
使用 limit 0 先创建表,在insert into table 导入数据
create table enterprise_wide_table as
select
a.entname,b.code_name as area,a.dom
,c.nic_id
,d.fulltitle
,a.opscope,a.entstatus
,a.regcap ,a.esdate
,date_part('year',now()) - to_char(a.esdate,'yyyy') as year
,e.ancheyear ,e.netinc ,e.liagro ,e.maibusinc ,e.vendinc
,a.empnum ,a.enttype_name
,case
when a.empnum >= '1000' and replace(e.maibusinc,'万','')>='40000' then '大'
when '1000'>a.empnum and replace(e.maibusinc,'万','')>='300' and '40000'>e.maibusinc and e.maibusinc>='2000' then '中'
when '300'>a.empnum and replace(e.maibusinc,'万','')>='20' and '2000'>e.maibusinc and e.maibusinc>='300' then '小'
when a.empnum< '20' and replace(e.maibusinc,'万','')<'300' then '微'
else 'NULL'
end as enterprise_scale
,f.pl_nums ,f.pr_nums
from
public.company a
inner join public.chongqign_area_code_csv b on a.domdistrict = b.code::varchar
left join public.company_class c on a.entid = c.entid and (substr(c.nic_id ,1,1)='B' or substr(c.nic_id ,1,1)='C' or substr(c.nic_id ,1,1)='D')
left join public.code_nic d on substr(c.nic_id ,1,1) = d.code
left join public.company_ar_assetsinfo e on e.entid = a.entid
left join public.nacao_techindex f on f.entid = a.entid limit 0
insert into enterprise_wide_table
select
a.entname,b.code_name as area,a.dom
,c.nic_id
,d.fulltitle
,a.opscope,a.entstatus
,a.regcap ,a.esdate
,date_part('year',now()) - to_char(a.esdate,'yyyy') as year
,e.ancheyear ,e.netinc ,e.liagro ,e.maibusinc ,e.vendinc
,a.empnum ,a.enttype_name
,case
when a.empnum >= '1000' and replace(e.maibusinc,'万','')>='40000' then '大'
when '1000'>a.empnum and replace(e.maibusinc,'万','')>='300' and '40000'>e.maibusinc and e.maibusinc>='2000' then '中'
when '300'>a.empnum and replace(e.maibusinc,'万','')>='20' and '2000'>e.maibusinc and e.maibusinc>='300' then '小'
when a.empnum< '20' and replace(e.maibusinc,'万','')<'300' then '微'
else 'NULL'
end as enterprise_scale
,f.pl_nums ,f.pr_nums
from
public.chongqign_area_code_temporary a
inner join public.chongqign_area_code_csv b on a.domdistrict = b.code::varchar
left join public.company_class c on a.entid = c.entid and (substr(c.nic_id ,1,1)='B' or substr(c.nic_id ,1,1)='C' or substr(c.nic_id ,1,1)='D')
left join public.code_nic d on substr(c.nic_id ,1,1) = d.code
left join public.company_ar_assetsinfo e on e.entid = a.entid
left join public.nacao_techindex f on f.entid = a.entid