Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojF4Q-0006JF-FV for pgsql-general@arkaria.postgresql.org; Fri, 14 Oct 2022 07:25:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ojF4P-0003LL-CE for pgsql-general@arkaria.postgresql.org; Fri, 14 Oct 2022 07:25:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oj4d0-0006Ng-9E for pgsql-general@lists.postgresql.org; Thu, 13 Oct 2022 20:16:26 +0000 Received: from portal-smtp-out.hot.ee ([194.126.101.125]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oj4cv-0000tS-OM for pgsql-general@postgresql.org; Thu, 13 Oct 2022 20:16:24 +0000 Received: from localhost (localhost [127.0.0.1]) by vm-hot-relay10.estpak.ee (Postfix) with ESMTP id CAC7C3349 for ; Thu, 13 Oct 2022 23:16:17 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at vm-hot-relay10.estpak.ee Received: from portal-smtp-out.hot.ee ([127.0.0.1]) by localhost (vm-hot-relay10.estpak.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 82wcQhJDsebA for ; Thu, 13 Oct 2022 23:16:15 +0300 (EEST) Received: from mail.hot.ee (hot-relayhost2.estpak.ee [213.180.2.80]) by vm-hot-relay10.estpak.ee (Postfix) with ESMTP id 6A4E232B9 for ; Thu, 13 Oct 2022 23:16:15 +0300 (EEST) Content-Type: multipart/alternative; boundary="------------12W3yS0o2lqjApOLzUHSGPXX" Message-ID: <86fe1ce7-3d6f-b723-b0fc-0eb796100588@hot.ee> Date: Thu, 13 Oct 2022 23:16:09 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: et To: pgsql-general From: Andrus Subject: How to return argument data type from sql function List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------12W3yS0o2lqjApOLzUHSGPXX Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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. --------------12W3yS0o2lqjApOLzUHSGPXX Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

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.

--------------12W3yS0o2lqjApOLzUHSGPXX--