Re: How to return argument data type from sql function - Mailing list pgsql-general

From Tom Lane
Subject Re: How to return argument data type from sql function
Date
Msg-id 1417737.1665782660@sss.pgh.pa.us
Whole thread Raw
In response to Re: How to return argument data type from sql function  (Andrus <kobruleht2@hot.ee>)
Responses Re: How to return argument data type from sql function
List 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 by date:

Previous
From: Andrus
Date:
Subject: Re: How to return argument data type from sql function
Next
From: "David G. Johnston"
Date:
Subject: Re: How to return argument data type from sql function