is there a way to determine the attributes of anyelement - Mailing list pgsql-general

From chrisj
Subject is there a way to determine the attributes of anyelement
Date
Msg-id 9951488.post@talk.nabble.com
Whole thread Raw
List pgsql-general
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.


pgsql-general by date:

Previous
From: Robert Treat
Date:
Subject: Re: What about SkyTools?
Next
From: SCassidy@overlandstorage.com
Date:
Subject: Re: SQL - finding next date