How to write a query which bring columns as output in the following code

50 views Asked by At
-- FUNCTION: select vehicle.sp_get_bodytypes_count_by_category()

-- DROP FUNCTION IF EXISTS vehicle.sp_get_bodytypes_count_by_category();

CREATE OR REPLACE FUNCTION vehicle.sp_get_bodytypes_count_by_category(
    )
    RETURNS TABLE(intersecting_rows bigint, category_id bigint, category_name text) 
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE PARALLEL UNSAFE
    ROWS 1000

AS $BODY$
BEGIN
    RETURN QUERY 
        SELECT COUNT(*) AS intersecting_rows, category.category_id, category.category_name::text
        FROM vehicle.category
        INNER JOIN vehicle.bodytype ON bodytype.category_id = category.category_id
        GROUP BY category.category_id, category.category_name
        ORDER BY category.category_id;
END;
$BODY$;

ALTER FUNCTION vehicle.sp_get_bodytypes_count_by_category()
    OWNER TO postgres;

The outpur it beings is just one column with values such as (4 , 1 , cars)

But I want the 4 , 1 and cars to be in different columns

Please can convey what changes do I need to do

0

There are 0 answers