English 中文(简体)
在邮政局职能中申请一名JSON Array的问题
原标题:Issue with Appending a JSON Array in a PostgreSQL Function

我在试图在邮政总局职能范围内将一阵列或目标排入另一阵列时遇到一个问题。 看来,阵列——申请功能正在将JSON作为扼杀,导致产出出现出乎意料的形式。

目前,我正在取得这样的成果:

{"{"category_id":8,"category_name":"08 Candy","is_active":true,"category_name_app":"Candy","display_order":7}"} However, I d like the output to be in this format so that I can easily decode it in my code:

[}

我的职能逻辑如下:

    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;
问题回答




相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签