pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrus <kobruleht2@hot.ee>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How to return argument data type from sql function
Date: Fri, 14 Oct 2022 17:24:20 -0400
Message-ID: <1417737.1665782660@sss.pgh.pa.us> (raw)
In-Reply-To: <12a74d8c-58ac-f14c-39c7-3730362e08e7@hot.ee>
References: <86fe1ce7-3d6f-b723-b0fc-0eb796100588@hot.ee>
	<1185464.1665759357@sss.pgh.pa.us>
	<12a74d8c-58ac-f14c-39c7-3730362e08e7@hot.ee>

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





view thread (9+ messages)  latest in thread

Message-ID: <1417737.1665782660@sss.pgh.pa.us>
Permalink:  ../1417737.1665782660@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1417737.1665782660@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kobruleht2@hot.ee, adrian.klaver@aklaver.com
  Subject: Re: How to return argument data type from sql function
  In-Reply-To: <1417737.1665782660@sss.pgh.pa.us>
  References: <86fe1ce7-3d6f-b723-b0fc-0eb796100588@hot.ee> <1185464.1665759357@sss.pgh.pa.us> <12a74d8c-58ac-f14c-39c7-3730362e08e7@hot.ee> <1417737.1665782660@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox