无法将超过 100 个参数传递给 json_build_object 的函数

问题描述 投票:0回答:1

无法将超过 100 个参数传递给 json_build_object 的函数,尝试从表的列构建 json。但它给了我错误,无法传递超过 100 个参数,但参数计数未超过 100。

代码如下:

array_agg(json_build_object
(
    'QuotaName',quota_name,
    'QuotaId',quota_id,
    'CellId',COALESCE(cell_id,0),
    'ValidPanelistCountOtherMedias',COALESCE(valid_panelist_count,0) ,
    'ValidPanelistCountMM',COALESCE(mm_valid_panelist_count,0) ,
    'Gender',COALESCE(replace(replace(replace(gender,',',':'),']',''),'[',''),''),
    'Occupation',COALESCE(replace(replace(replace(occupation_id,',',':'),']',''),'[',''),''),
    'Industry',COALESCE(replace(replace(replace(industry_id,',',':'),']',''),'[',''),''),
    'Prefecture',COALESCE(replace(replace(replace(prefecture_id,',',':'),']',''),'[',''),''),
    'Age1',COALESCE(replace(replace(replace(age,',',':'),']',''),'[',''),''),
    'Age2',COALESCE(replace(replace(replace(age2,',',':'),']',''),'[',''),''),
    'MaritalStatus',COALESCE(replace(replace(replace(marital_status,',',':'),']',''),'[',''),''),
    'HouseHoldIncome',COALESCE(replace(replace(replace(house_income_id,',',':'),']',''),'[',''),''),
    'PersonalIncome',COALESCE(replace(replace(replace(personal_income_id,',',':'),']',''),'[',''),''),
    'hasChild',COALESCE(replace(replace(replace(has_child,',',':'),']',''),'[',''),''),
    'MediaId',COALESCE(replace(replace(replace(media_id,',',':'),']',''),'[',''),''),
    'DeviceUsed',COALESCE(replace(replace(replace(device_type,',',':'),']',''),'[',''),''),
    'PanelistStatus','',
    'IR1', COALESCE(ir_1,1) ,
    'IR2', COALESCE(ir_2,1) ,
    'IR3', COALESCE(ir_3,1) ,
    'Population',COALESCE(population,0),
    'MainSurveySampleHopes',  COALESCE(sample_hope_main_survey,0) ,
    'ScreeningSurveySampleHopes', COALESCE(sample_hope_main_scr,0),
    'ParticipateIntentionMM' ,COALESCE(participate_intention_mm,0) ,
    'ParticipateIntentionOthers' ,COALESCE(participate_intention,0) ,
    'AcquisitionRate', COALESCE(acquisition_rate,0) , 
    'PCEnvironment', COALESCE(case when survey_type >3 then 1 else pc_env end,0) ,
    'NetworkEnvironment',COALESCE(case when survey_type >3 then 1 else network_env  end,0) ,
    'PCEnvironmentMM',COALESCE(case when survey_type >3 then 1 else pc_env_mm  end,0),
    'NetworkEnvironmentMM',COALESCE(case when survey_type >3 then 1 else network_env_mm  end,0) ,
    'ControlQuotient',COALESCE(control_quotient,0)/100 ,
    'ResponseofSCR24' , COALESCE(res_of_scr_24,0),
    'ResponseofSCR48' ,COALESCE(res_of_scr_48,0) ,
    'ResponseofSCR72' ,COALESCE(res_of_scr_72,0) ,  
    'ResponseofSCR168' ,COALESCE(res_of_scr_168,0),     
    'ResponseofMAIN24' ,COALESCE(res_of_main_24,0) ,        
    'ResponseofMAIN48' , COALESCE(res_of_main_48,0) ,       
    'ResponseofMAIN72' , COALESCE(res_of_main_72,0) ,       
    'ResponseofMAIN168' , COALESCE(res_of_main_168,0),        
    'ResponseofSCR24MM' ,COALESCE(res_of_scr_24_mm,0) ,
    'ResponseofSCR48MM' , COALESCE(res_of_scr_48_mm,0),
    'ResponseofSCR72MM' , COALESCE(res_of_scr_72_mm,0) ,    
    'ResponseofSCR168MM' ,COALESCE(res_of_scr_168_mm,0) ,       
    'ResponseofMAIN24MM' ,COALESCE(res_of_main_24_mm,0),        
    'ResponseofMAIN48MM' ,COALESCE(res_of_main_48_mm,0),        
    'ResponseofMAIN72MM' ,COALESCE(res_of_main_72_mm,0),        
    'ResponseofMAIN168MM' ,COALESCE(res_of_main_168_mm,0),
    'ResponseofMAINIntegrationType',0.9,-- this value is based on answer_estimate_list_details_v3
    'ParticipationIntention',COALESCE(participate_intention,0),
    'MostRecentParticipation',COALESCE(most_recent_exclusions,0)
json postgresql-9.6
1个回答
3
投票

今天早些时候我遇到了完全相同的问题。经过一番研究,我发现 JSONB 结果可以串联。所以你应该使用

JSONB_BUILD_OBJECT
而不是
JSON_BUILD_OBJECT
。然后,将事情分开,这样你就有多个
JSONB_BUILD_OBJECT
调用,这些调用与
||
组合在一起。您还需要
JSONB_AGG
将结果转换为数组。

JSONB_AGG(
    JSONB_BUILD_OBJECT (
        'QuotaName',quota_name,
        'QuotaId',quota_id,
        'CellId',COALESCE(cell_id,0),
        'ValidPanelistCountOtherMedias',COALESCE(valid_panelist_count,0) ,
        'ValidPanelistCountMM',COALESCE(mm_valid_panelist_count,0) ,
        'Gender',COALESCE(replace(replace(replace(gender,',',':'),']',''),'[',''),''),
        'Occupation',COALESCE(replace(replace(replace(occupation_id,',',':'),']',''),'[',''),''),
        'Industry',COALESCE(replace(replace(replace(industry_id,',',':'),']',''),'[',''),''),
        'Prefecture',COALESCE(replace(replace(replace(prefecture_id,',',':'),']',''),'[',''),''),
        'Age1',COALESCE(replace(replace(replace(age,',',':'),']',''),'[',''),''),
        'Age2',COALESCE(replace(replace(replace(age2,',',':'),']',''),'[',''),''),
        'MaritalStatus',COALESCE(replace(replace(replace(marital_status,',',':'),']',''),'[',''),''),
        'HouseHoldIncome',COALESCE(replace(replace(replace(house_income_id,',',':'),']',''),'[',''),''),
        'PersonalIncome',COALESCE(replace(replace(replace(personal_income_id,',',':'),']',''),'[',''),''),
        'hasChild',COALESCE(replace(replace(replace(has_child,',',':'),']',''),'[',''),''),
        'MediaId',COALESCE(replace(replace(replace(media_id,',',':'),']',''),'[',''),''),
        'DeviceUsed',COALESCE(replace(replace(replace(device_type,',',':'),']',''),'[',''),''),
        'PanelistStatus','',
        'IR1', COALESCE(ir_1,1) ,
        'IR2', COALESCE(ir_2,1) ,
        'IR3', COALESCE(ir_3,1) ,
        'Population',COALESCE(population,0),
        'MainSurveySampleHopes',  COALESCE(sample_hope_main_survey,0) ,
        'ScreeningSurveySampleHopes', COALESCE(sample_hope_main_scr,0),
        'ParticipateIntentionMM' ,COALESCE(participate_intention_mm,0) ,
        'ParticipateIntentionOthers' ,COALESCE(participate_intention,0) ,
        'AcquisitionRate', COALESCE(acquisition_rate,0) , 
        'PCEnvironment', COALESCE(case when survey_type >3 then 1 else pc_env end,0) ,
        'NetworkEnvironment',COALESCE(case when survey_type >3 then 1 else network_env  end,0) ,
        'PCEnvironmentMM',COALESCE(case when survey_type >3 then 1 else pc_env_mm  end,0),
        'NetworkEnvironmentMM',COALESCE(case when survey_type >3 then 1 else network_env_mm  end,0) ,
        'ControlQuotient',COALESCE(control_quotient,0)/100 ,
        'ResponseofSCR24' , COALESCE(res_of_scr_24,0),
        'ResponseofSCR48' ,COALESCE(res_of_scr_48,0) ,
        'ResponseofSCR72' ,COALESCE(res_of_scr_72,0) ,  
        'ResponseofSCR168' ,COALESCE(res_of_scr_168,0),     
        'ResponseofMAIN24' ,COALESCE(res_of_main_24,0) ,        
        'ResponseofMAIN48' , COALESCE(res_of_main_48,0) ,       
        'ResponseofMAIN72' , COALESCE(res_of_main_72,0) ,       
        'ResponseofMAIN168' , COALESCE(res_of_main_168,0),        
        'ResponseofSCR24MM' ,COALESCE(res_of_scr_24_mm,0) ,
        'ResponseofSCR48MM' , COALESCE(res_of_scr_48_mm,0),
        'ResponseofSCR72MM' , COALESCE(res_of_scr_72_mm,0) ,    
        'ResponseofSCR168MM' ,COALESCE(res_of_scr_168_mm,0) ,       
        'ResponseofMAIN24MM' ,COALESCE(res_of_main_24_mm,0),        
        'ResponseofMAIN48MM' ,COALESCE(res_of_main_48_mm,0),        
        'ResponseofMAIN72MM' ,COALESCE(res_of_main_72_mm,0),        
        'ResponseofMAIN168MM' ,COALESCE(res_of_main_168_mm,0)
    ) ||
    JSONB_BUILD_OBJECT (
        'ResponseofMAINIntegrationType',0.9,-- this value is based on answer_estimate_list_details_v3
        'ParticipationIntention',COALESCE(participate_intention,0),
        'MostRecentParticipation',COALESCE(most_recent_exclusions,0)
    )
)

我从这里的文档中得到了这个 - https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-JSONB-OP-TABLE:~:text=jsonb%20%7C%7C%20jsonb %20%E2%86%92%20jsonb

寻找

jsonb || jsonb

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.