Search Postgresql Archives

is there a way to determine the attributes of anyelement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have written a simple procedure that accepts anyarray, and concatinates the
elements separated by a space and returns the result to anyelement.

I know when I call this function I will always be passing varchars.  If the
length of the resultant concatination
is longer than the maximum length of the return varchar I want to truncate
at the max.  Since I don't know the max length of the return varchar I now
get an error in this situation:
ERROR:  value too long for type character varying(10)

is there a way to determine the maximum length of the varchar of anyelement
inside the function?

Here is my simple function:

create or replace function concat_arr( p_array      anyarray
                                     ) returns anyelement as \$\$
DECLARE
    out_char ALIAS FOR \$0;
BEGIN
  out_char := '' ;
  FOR i IN 1..array_upper(p_array, 1) LOOP
    if i <> 1 then
      out_char := out_char || ' ' || p_array[i] ;
    else
      out_char := out_char || p_array[i] ;
    end if ;
  END LOOP;
  return (out_char) ;
END;

\$\$ LANGUAGE plpgsql
;

-- 
View this message in context: http://www.nabble.com/is-there-a-way-to-determine-the-attributes-of-anyelement-tf3562903.html#a9951488
Sent from the PostgreSQL - general mailing list archive at Nabble.com.



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux