Skip to content

How can I use the cubes and sum a json column? #505

@matheusbento

Description

@matheusbento

Hello guys, I'm working with Postgresql + Cubes.

I have a JSONB column, which is a array of numbers. how can I modify the cubes to accept the sum of this pattern?

image

I already found a way to do the SUM in the SQL:

SELECT index
    , (SELECT sum(nr::numeric) FROM jsonb_array_elements(snx_wavelengths) nr) AS wavelength_sum
FROM   tbl
ORDER  BY 1;

but I don't know how to implement this part in existent code:
(SELECT sum(nr::numeric) FROM jsonb_array_elements(snx_wavelengths) nr) AS wavelength_sum

I already tried to put the SQL direct on the functions, but no success.

image

In the future, I would like to create new functions like avg, standard deviation, etc..

Anyone can give me some path how to do that?

@Stiivi @pktippa

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions