【发布时间】:2021-12-31 03:06:29
【问题描述】:
我正在尝试将 json 数组或对象附加到 json 数组中,但 array_append 总是将 json 作为字符串插入。
我的结果是;
{"{"category_id":8,"category_name":"08 Candy","is_active":true,"category_name_app":"Candy","display_order":7}"}
但我希望它是这样的。所以我可以在我的代码中对它们进行 json_decode。
[{"category_id":8,"category_name":"08 Candy","is_active":true,"category_name_app":"Candy","display_order":7}]
这是我的功能逻辑
for all_categories in select * from categories where is_active = '1' loop
show_at_homepage = 0;
for current_subcat in select * from public."V_category_to_sub_category_w_names" where category_id = all_categories.category_id and sub_category_is_active = '1' loop
select * into product_count from public."V_APP_products_w_sub_categories" where sub_category_id = current_subcat.sub_category_id and store_id = get_store_id and is_deleted='0';
if count(product_count) > 0 then
show_at_homepage = 1;
end if;
end loop;
if show_at_homepage = 1 then
select row_to_json(all_categories) into cat_json;
select array_append(my_json_result_array,cat_json) into my_json_result_array;
end if;
end loop;
return my_json_result_array;
【问题讨论】:
标签: arrays json postgresql stored-procedures