Andrus <kobruleht2@hot.ee> writes:
> I tried
> create or replace FUNCTION torus(eevarus bpchar) returns bpchar
> immutable AS $f$
> select translate( $1, U&'\00f8\00e9', U&'\0451\0439' );
> $f$ LANGUAGE SQL ;
> but it still returns result without trailing spaces. So it is not working.
As I said, width constraints don't propagate through functions.
> I tried
> create or replace FUNCTION torus(eevarus anylement ) returns anylement
> immutable AS $f$
> select translate( $1, U&'\00f8\00e9', U&'\0451\0439' );
> $f$ LANGUAGE SQL ;
> but got error
> type anyelement does not exists.
Might've helped to spell "anyelement" correctly ;-). However, if you're
insistent on those trailing spaces, this approach won't change anything
about that.
> select rpad ( torus(charcol), colwidth('public', 'test', 'charcol') )
> FROM Test
Yeah, you could do that if you have the column information at hand.
> How to remove p_namespace parameter from colwidth()?
select atttypmod-4 from pg_attribute
where attrelid = p_table::regclass and attname = p_field
Personally I'd also throw in "... and atttypid = 'bpchar'::regtype",
because that atttypmod calculation will give you garbage for types
other than bpchar and varchar.
regards, tom lane