arrayspostgresqlgreenplumpostgresql-8.2

Finding array length in postgres


I tried array_upper(array(Value)) and array_upper((Value):array[]) but was getting syntax error.

Value : data type is int []; I am expecting the result as below table:

 Pname  week_date      Value    array_length
    5773    6/8/2013    {29}            1
    5773    3/30/2013   {27}            1
    5773    3/16/2013   {138,3,4}       3
    5773    3/9/2013    {37,8}          2
    5773    1/19/2013   {66}            1
    5773    1/5/2013    {49,50,50,56}   4

But this works fine

select array_upper(array[1,2,3,6], 1)

I need to use Value column and find out the length of that value array

postgres version : 8.2


Solution

  • That should work:

    select array_upper ( value, 1 ) from table_name_here;
    

    Note: 'VALUE' is reserved keyword in SQL, so it is not recommended to use it as a column name. See: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html