Re: How to return argument data type from sql function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to return argument data type from sql function
Дата
Msg-id 1417737.1665782660@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How to return argument data type from sql function  (Andrus <kobruleht2@hot.ee>)
Ответы Re: How to return argument data type from sql function  (Andrus <kobruleht2@hot.ee>)
Список pgsql-general
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



В списке pgsql-general по дате отправления:

Предыдущее
От: Andrus
Дата:
Сообщение: Re: How to return argument data type from sql function
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: How to return argument data type from sql function