2

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

mu is too short
  • 426,620
  • 70
  • 833
  • 800
user2569524
  • 1,651
  • 7
  • 32
  • 57

1 Answers1

5

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

Tomasz Siorek
  • 701
  • 5
  • 10
  • no it doesnt work it throws an error : function array_upper(integer[]) does not exist – user2569524 Feb 27 '14 at 20:19
  • 2
    @user2569524: PostgreSQL 8.2 has [`array_upper(anyarray,int)`](http://www.postgresql.org/docs/8.2/interactive/functions-array.html#ARRAY-FUNCTIONS-TABLE) so it should work. Your error message suggests that you're trying to use `array_upper(value)` instead of `array_upper(value, 1)`. – mu is too short Feb 27 '14 at 20:43