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

From Andrus
Subject How to return argument data type from sql function
Date
Msg-id 86fe1ce7-3d6f-b723-b0fc-0eb796100588@hot.ee
Whole thread Raw
Responses Re: How to return argument data type from sql function
List pgsql-general

PostgreSQL 12.2+ function is defined as

    create FUNCTION torus(eevarus text) returns text immutable AS $f$
     select translate( $1, U&'\00f8\00e9', U&'\0451\0439' );
    $f$ LANGUAGE SQL ;

This function is called as CHAR(n) or text columns like

    create temp table test (
    charcol char(10),
    textcol text );
    
    insert into test values ('test', 'test');
    
    select torus(charcol), torus(textcol), charcol

torus(charcol) returns text column and loses original column width. How to force torus() to return argument type:

if char(n) column is passed as argument, torus() should also return char(n) data type.
I tried to use bpchar instead on text

    create or replace FUNCTION torusbpchar(eevarus bpchar) returns bpchar immutable AS $f$
     select translate( $1, U&'\00f8\00e9', U&'\0451\0439' );
    $f$ LANGUAGE SQL ;

torusbpchar(charcol) still returns text data type.

npgsql DataReader is used to get data.

Andrus.

pgsql-general by date:

Previous
From: Erik Wienhold
Date:
Subject: Re: Exponentiation confusion
Next
From: gzh
Date:
Subject: Re:Re: Re: Does psqlodbc_11_01_0000-x64 support special characters?