pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
sum of numeric column
5+ messages / 2 participants
[nested] [flat]

* sum of numeric column
@ 2020-12-10 00:46 avi Singh <avisingh19811981@gmail.com>
  2020-12-10 00:48 ` Re: sum of numeric column Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 5+ messages in thread

From: avi Singh @ 2020-12-10 00:46 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

I have a table structure and want to do a sum of column type i.e numeric.
How can I do it ? when i try sum function i get this error

ERROR:  function sum(numeric[]) does not exist

Can anyone please help me with this ?

           Column           |           Type           | Collation |
Nullable | Default
----------------------------+--------------------------+-----------+----------+---------
 grid_id                    | bigint                   |           | not
null |
 as_of_date                 | date                     |           | not
null |
 cell_id                    | bigint                   |           | not
null |
 last_event_timestamp_local | timestamp with time zone |           |
   |
 last_event_id              | bigint                   |           |
   |
 column_id                  | bigint                   |           |
   |
 column_name                | character varying(50)    |           |
   |
 row_id                     | bigint                   |           |
   |
 data_type_id               | smallint                 |           |
   |
 data_numeric               | numeric[]                |           |
   |
 data_string                | character varying[]      |           |
   |

e.g. of values in numeric type column

 data_numeric
--------------
 {2.0}
 {1.0}

Regards
Prabhjot

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: sum of numeric column
  2020-12-10 00:46 sum of numeric column avi Singh <avisingh19811981@gmail.com>
@ 2020-12-10 00:48 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2020-12-10 01:04   ` Re: sum of numeric column avi Singh <avisingh19811981@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Adrian Klaver @ 2020-12-10 00:48 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 12/9/20 4:46 PM, avi Singh wrote:
> I have a table structure and want to do a sum of column type i.e 
> numeric. How can I do it ? when i try sum function i get this error

You don't have a numeric type you have a numeric array type.

> 
> ERROR:  function sum(numeric[]) does not exist

Hence the error above.

> 
> Can anyone please help me with this ?

What do you want to do with the array?

> 
>             Column           |           Type           | Collation | 
> Nullable | Default
> ----------------------------+--------------------------+-----------+----------+---------
>   grid_id                    | bigint                   |           | 
> not null |
>   as_of_date                 | date                     |           | 
> not null |
>   cell_id                    | bigint                   |           | 
> not null |
>   last_event_timestamp_local | timestamp with time zone |           |   
>         |
>   last_event_id              | bigint                   |           |   
>         |
>   column_id                  | bigint                   |           |   
>         |
>   column_name                | character varying(50)    |           |   
>         |
>   row_id                     | bigint                   |           |   
>         |
>   data_type_id               | smallint                 |           |   
>         |
>   data_numeric               | numeric[]                |           |   
>         |
>   data_string                | character varying[]      |           |   
>         |
> 
> e.g. of values in numeric type column
> 
>   data_numeric
> --------------
>   {2.0}
>   {1.0}
> 
> Regards
> Prabhjot


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: sum of numeric column
  2020-12-10 00:46 sum of numeric column avi Singh <avisingh19811981@gmail.com>
  2020-12-10 00:48 ` Re: sum of numeric column Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-12-10 01:04   ` avi Singh <avisingh19811981@gmail.com>
  2020-12-10 01:32     ` Re: sum of numeric column Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 5+ messages in thread

From: avi Singh @ 2020-12-10 01:04 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general@lists.postgresql.org

Thanks for your reply Adrian


What do you want to do with the array?
i want to do a sum of the values of numeric array type column e.g. below

data_numeric
--------------
 {2.0}
 {1.0}


(4 rows)



Regards


On Wed, Dec 9, 2020 at 4:49 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

> On 12/9/20 4:46 PM, avi Singh wrote:
> > I have a table structure and want to do a sum of column type i.e
> > numeric. How can I do it ? when i try sum function i get this error
>
> You don't have a numeric type you have a numeric array type.
>
> >
> > ERROR:  function sum(numeric[]) does not exist
>
> Hence the error above.
>
> >
> > Can anyone please help me with this ?
>
> What do you want to do with the array?
>
> >
> >             Column           |           Type           | Collation |
> > Nullable | Default
> >
> ----------------------------+--------------------------+-----------+----------+---------
> >   grid_id                    | bigint                   |           |
> > not null |
> >   as_of_date                 | date                     |           |
> > not null |
> >   cell_id                    | bigint                   |           |
> > not null |
> >   last_event_timestamp_local | timestamp with time zone |           |
> >         |
> >   last_event_id              | bigint                   |           |
> >         |
> >   column_id                  | bigint                   |           |
> >         |
> >   column_name                | character varying(50)    |           |
> >         |
> >   row_id                     | bigint                   |           |
> >         |
> >   data_type_id               | smallint                 |           |
> >         |
> >   data_numeric               | numeric[]                |           |
> >         |
> >   data_string                | character varying[]      |           |
> >         |
> >
> > e.g. of values in numeric type column
> >
> >   data_numeric
> > --------------
> >   {2.0}
> >   {1.0}
> >
> > Regards
> > Prabhjot
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
>
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: sum of numeric column
  2020-12-10 00:46 sum of numeric column avi Singh <avisingh19811981@gmail.com>
  2020-12-10 00:48 ` Re: sum of numeric column Adrian Klaver <adrian.klaver@aklaver.com>
  2020-12-10 01:04   ` Re: sum of numeric column avi Singh <avisingh19811981@gmail.com>
@ 2020-12-10 01:32     ` Adrian Klaver <adrian.klaver@aklaver.com>
  2020-12-10 03:35       ` Re: sum of numeric column avi Singh <avisingh19811981@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Adrian Klaver @ 2020-12-10 01:32 UTC (permalink / raw)
  To: avi Singh <avisingh19811981@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

On 12/9/20 5:04 PM, avi Singh wrote:
> Thanks for your reply Adrian
> 
> 
> What do you want to do with the array?
> i want to do a sum of the values of numeric array type column e.g. below
> data_numeric
> --------------
>   {2.0}
>   {1.0}

If you are going to have a single element arrays only then why not just 
use a numeric field?

To answer question:

select sum(data_numeric[1]) from some_table;

If you are going to have multi-element arrays then there are more questions:

1) Do you want sum horizontal in array?

2) If 1) then also vertical in column?

3) Do you want sum in 'columns' of arrays?

4) If 3) then what about missing data?

> 
> 
> (4 rows)
> 
> 
> 
> Regards
> 
> 



-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: sum of numeric column
  2020-12-10 00:46 sum of numeric column avi Singh <avisingh19811981@gmail.com>
  2020-12-10 00:48 ` Re: sum of numeric column Adrian Klaver <adrian.klaver@aklaver.com>
  2020-12-10 01:04   ` Re: sum of numeric column avi Singh <avisingh19811981@gmail.com>
  2020-12-10 01:32     ` Re: sum of numeric column Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-12-10 03:35       ` avi Singh <avisingh19811981@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: avi Singh @ 2020-12-10 03:35 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general@lists.postgresql.org

Thanks Adrian for pointing me in the right direction, i got it working


On Wed, Dec 9, 2020 at 5:32 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

> On 12/9/20 5:04 PM, avi Singh wrote:
> > Thanks for your reply Adrian
> >
> >
> > What do you want to do with the array?
> > i want to do a sum of the values of numeric array type column e.g. below
> > data_numeric
> > --------------
> >   {2.0}
> >   {1.0}
>
> If you are going to have a single element arrays only then why not just
> use a numeric field?
>
> To answer question:
>
> select sum(data_numeric[1]) from some_table;
>
> If you are going to have multi-element arrays then there are more
> questions:
>
> 1) Do you want sum horizontal in array?
>
> 2) If 1) then also vertical in column?
>
> 3) Do you want sum in 'columns' of arrays?
>
> 4) If 3) then what about missing data?
>
> >
> >
> > (4 rows)
> >
> >
> >
> > Regards
> >
> >
>
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2020-12-10 03:35 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 00:46 sum of numeric column avi Singh <avisingh19811981@gmail.com>
2020-12-10 00:48 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-12-10 01:04   ` avi Singh <avisingh19811981@gmail.com>
2020-12-10 01:32     ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-12-10 03:35       ` avi Singh <avisingh19811981@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox