Ice2burn
Ice2burn

Reputation: 691

PostgreSQL - return n-sized varchar from function

As I found in documentation:

Parenthesized type modifiers (e.g., the precision field for type numeric) are discarded by CREATE FUNCTION

Are there any alternatives to return varchar(N) type from plpgsql function?


question update:

On picture you can see that Name column recognised as varchar(128), however Number column is recognised as nonsized varchar

Result example

f_concat function returns: cast(res as varchar(255));

Upvotes: 2

Views: 677

Answers (1)

Nick Barnes
Nick Barnes

Reputation: 21356

You can preserve the type modifier for a function result by creating a domain. Postgres will use the underlying varchar(N) type when sending column descriptions to your client:

Upvotes: 4

Related Questions